[XeTeX] Bidipoem for dialogue poetry

Paul Isambert zappathustra at free.fr
Tue Oct 12 10:14:39 CEST 2010


  Le 12/10/2010 01:53, Gareth Hughes a écrit :
> Paul Isambert wrote:
>> Ok, the following works on your file, but I don't know how robust it is:
>>
>> %%%
>>
>> \newcount\LineNumber \newcount\templinenumber
>> \newdimen\linenumberskip \linenumberskip=6em
>> \chardef\linestep=2
>> \def\poemlinenumber{%
>>    \advance\LineNumber1
>>    \templinenumber=\LineNumber
>>    \computelinenumber
>>    }
>> \def\computelinenumber{%
>>    \ifnum\templinenumber>\linestep
>>      \advance\templinenumber-\linestep
>>      \expandafter\computelinenumber
>>    \else
>>      \ifnum\templinenumber=\linestep
>>        \leavevmode\rlap{\kern\linenumberskip\the\LineNumber}%
>>      \fi
>>    \fi
>>    }
>> \newenvironment{numberedpoem}
>>    {\everypar{\everypar{\poemlinenumber}}%
>>     \begin{traditionalpoem}}
>>    {\end{traditionalpoem}}
>>
>> %%%
>>
>> You poem should now be enclosed in the "numberedpoem" environment.
>> You can change \linestep (on line 3) to any value; if it is set /n/,
>> every /n/th line number is printed.
>> You can change \linenumberskip (on line 2), which sets the distance of
>> the line number to the margin.
>> This is not thoroughly tested! Sorry for the syntax, it's not LaTeX-like
>> (but you made me -- although you didn't ask! -- download so many
>> packages so your file can work than I need a little revenge :) ).
>>
>> Best,
>> Paul
>
> Thank you, Paul, for showing me how to do this. It looks good and is
> quite flexible. I have a couple more questions, if I may.
>
> 1) What is the best way of changing the positioning of the numbers so
> that they are on the right of the poem, or that they are on the inner or
> outer edge in documents that define these things? Is this best done by
> altering \linenumberskip?


For this point I have the following solution (needs two runs):

\makeatletter

\def\@writelinenumber#1{%
   \write\@mainaux{%
     
\noexpand\expandafter\gdef\noexpand\csname#1 at linenumber\noexpand\endcsname{\the\count0}}% 

   }
\newcount\@linenumbercount
\newcount\LineNumber \newcount\templinenumber
\newdimen\linenumberskip \linenumberskip=5em
\chardef\linestep=2
\long\def\poemlinenumber{%
   \advance\LineNumber1
   \templinenumber=\LineNumber
   \computelinenumber
   }
\def\computelinenumber{%
   \ifnum\templinenumber>\linestep
     \advance\templinenumber-\linestep
     \expandafter\computelinenumber
   \else
     \ifnum\templinenumber=\linestep
       \global\advance\@linenumbercount1
       \expandafter\@writelinenumber\expandafter{\the\@linenumbercount}%
       \ifcsname\the\@linenumbercount @linenumber\endcsname
         \ifodd\csname\the\@linenumbercount @linenumber\endcsname\relax
           
\leavevmode\rlap{\kern\dimexpr\hsize-\linenumberskip\relax\the\LineNumber}%
         \else
           \leavevmode\rlap{\kern\linenumberskip\the\LineNumber}%
         \fi
       \else
         \leavevmode\rlap{\kern\linenumberskip\the\LineNumber}%
       \fi
     \fi
   \fi
   }
\newenvironment{numberedpoem}
   {\everypar{\everypar{\poemlinenumber}}%
    \begin{traditionalpoem}}
   {\end{traditionalpoem}}


\makeatother



> 2) As it stands, a blank line, indicating a stanza break, is counted as
> a line of the poem. How can this code be altered so as not to count the
> blank lines between stanzas?
For this one, though, I don't have any solution. I've investigated 
bidipoem a bit, and it does its job with alignments, and doesn't treat a 
blank line simply as \par. So our macro fires on blank lines...

Of course a hack of bidipoem is possible (but I won't do it, no time to 
do so), but I think it'd be easier to ask the author to implement such a 
feature (line numbers in poems aren't uncommon...). Or find another way 
to input a blank line...

Best,
Paul


More information about the XeTeX mailing list