2

To put faint, non-kerning lines between syllables, is there a way for the command to detect if it is adjacent to a space and if so to (a) restore the space, and (b) place the bar midway? (Alternately, user could place \m between spaces, like to be, \m or not \m to be, in which case code should detect that and back up half a space to place bar.)

PSEUDOCODE:

Am I adjacent to a space?

  • Y: restore the space (that I have destroyed by coming before it and being a command), and place bar in the middle of that space

  • N: place bar between letters without impacting letter spacing

     \documentclass[varwidth]{standalone}
     \usepackage{xcolor}
    

    \newcommand\m{% {% \color{gray!50}% \rule[-\dp\strutbox]{0.3pt}% {\baselineskip}% }% }%

    \begin{document}

    \noindent To be,\m or not\m to be,\m that is\m the question:\ Whether\m 'tis nob\m ler in\m the mind\m to suffer\ The slings\m and ar\m rows of\m outrage\m ous fortune,\ Or to\m take arms\m against\m a sea\m of troubles

    \end{document}

commonhare
  • 2,630
  • you can test for a space but there is no space after \m it would be easier to use a syntax such as | so To be,| or not| to be and nob|ler then the space is tokenised (or not) – David Carlisle Jan 25 '23 at 12:02
  • @DavidCarlisle my goal is to have the spacing of the original line remain unchanged by the placement of these faint bars. – commonhare Jan 25 '23 at 12:07
  • yes but do you really need \m it would be much easier to use | (which you still define to be the grey rule). Also what to you mean by unchanged do you want nob|ler the same width as nobler with the rule over-printing the bl slightly, or do you want nob|ler to be wider by the width of the rule? – David Carlisle Jan 25 '23 at 12:16
  • You could also consider making | an active character and define it as whatever kind of vertical rule you want. – Gaussler Jan 25 '23 at 12:49
  • @DavidCarlisle oh no, I definitely do not need \m! Oooo, I like the idea of "wider by the width of the rule", both for words and inter-word spaces. – commonhare Jan 25 '23 at 13:13
  • @Gaussler (also to David Carlisle): I confess I was unaware one could embed a command inside a single character. – commonhare Jan 25 '23 at 13:14
  • @commonhare Simply do \catcode`|=\active and then \def|{<whatever you want>}. – Gaussler Jan 25 '23 at 13:22
  • @Gaussler yes exactly, that's what I meant. – David Carlisle Jan 25 '23 at 14:38

1 Answers1

4

enter image description here

 \documentclass[varwidth]{standalone}
 \usepackage{xcolor}
\makeatletter
% just do this locally if you need | for tables or tikz etc
\catcode`\|\active 
 \newcommand|{\futurelet\poetry@tmp\poetry@bar}

\newcommand\poetry@bar{% \ifhmode\unskip\fi \ifx\poetry@tmp@sptoken % half word space see % https://tex.stackexchange.com/questions/88991/what-do-different-fontdimennum-mean/ \hskip.5\fontdimen2\font@plus.5\fontdimen3\font@minus.5\fontdimen4\font \fi {\color{gray!50}% \rule[-\dp\strutbox]{0.3pt}% {\baselineskip}}% \ifx\poetry@tmp X\fi \ifx\poetry@tmp@sptoken % half word space \hskip.5\fontdimen2\font@plus.5\fontdimen3\font@minus.5\fontdimen4\font \fi \ignorespaces }

\makeatother \begin{document} \setlength\parskip{0pt}

To be,| or not| to be,| that is| the question:\ Whether| 'tis nob|ler in| the mind| to suffer\ The slings| and ar|rows of| outrage|ous fortune,\ Or to| take arms| against| a sea| of troubles

\end{document}

| is easier to input than \m and avoids losing the space, so you can test for a space with \futurelet

David Carlisle
  • 757,742