My TeX code (including parameters in command definitions) that creates lyrics sheets and chord sheets of songs is generated dynamically by other code accessing database data and processing it line by line, so my stripped-down MWE may seem odd, but bear with me.
The intent of the code snippet you see is that in addition to the basic line spacing associated with the two font sizes (which matters when lines wrap), an additional 0.3em is between each "paragraph" (line of lyrics) for clarity. However, whenever a line of romaji occurs immediately after a line of Japanese, I don't want that extra parskip, so I try to negate it with a \vspace
of the negative of the same amount. So far, so good – the following file works:
\documentclass{ujarticle}
\usepackage[a4paper, margin=6mm]{geometry}
\usepackage{needspace}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newcommand{\romaji}[1]{\begingroup\fontsize{10}{11.5}\selectfont
{#1}\endgroup}
\newenvironment{stanza}
{
\vspace{1em}
\setlength{\parskip}{0.3em}
\fontsize{12}{13.5}\selectfont
\begin{samepage}
}
{
\end{samepage}
}
\begin{document}
\sffamily
\gtfamily
\raggedright
\raggedbottom
\pagestyle{empty}
\begin{stanza}
賛美して目を向けてる あなたに\par
\vspace{-0.3em}\nopagebreak
\romaji{sambi\ shite\ me\ o\ muketeru,\ anata\ ni\par}
\nopagebreak
もとめて待ち望んでる あなたを\par
\vspace{-0.3em}\nopagebreak
\romaji{motomete\ machi\ nozonderu,\ anata\ o\par}
\end{stanza}
\end{document}
But when a style for romaji is added (in my test case, italic), it breaks and I get a huge hunk of extra space. The only difference between the left and right screenshots below is the addition of \textit{...}
in the romaji command definition:
\newcommand{\romaji}[1]{\begingroup\fontsize{10}{11.5}\selectfont
\textit{{#1}}\endgroup}
Here is the output of the two:
mysterious spacing http://l4jp.com/tmp/TeX-tests.png
The complaint in the log file is:
Runaway argument?
{{sambi\ shite\ me\ o\ muketeru,\ anata\ ni !
Paragraph ended before \text@command was complete.
That makes sense, but I only get that error when the \textit{}
is there – perhaps the parser can't navigate the double braces? Moving the \par
after the closing brace makes the error go away, but then the \vspace
is ignored in all cases.
Best Answer
The problem lies in how you're telling
\romaji
to use italics. The command\textit{}
expects an argument, thus cannot handle paragraph breaks. This is why it complains when it encounters\par
. One option is to simply omit\par
from the end of every\romaji
command. Perhaps a better option is to use{\itshape …}
, which applies to whatever follows and can handle paragraph breaks. See the following MWE for an example.