1

I want to paragraph-break a text at a specific spot, but only if the text is too long for the line. In the MWE below, the first text fits the line width, but the second does not. Of course, I could just manually add a \par whenever the text turns out to be too long, but I would like LaTeX to spot this automatically [on a second pass, perhaps?] and break the line before the \Rbar symbol.

\documentclass[]{article}
\usepackage{xcolor}
\usepackage{gregoriotex}

\begin{document}%
\newcommand\versicle[1]{%
    \textbf{\color{red}\Vbar. }{#1 }%
    \textbf{\color{red}\Rbar. }{#2}}%
%
%This fits in one line
\versicle{Dóminus vobíscum.}{Et cum spíritu túo.}\par%
%
%This should line break at the \Rbar.
\versicle{Panem de cælo præstitísti eis, allelúia.}{Omne delectaméntum in se habéntem, allelúia.}%
\end{document}

The code produces this: enter image description here

I'd like to get this:enter image description here

3

You can test if the content width has exceeded \linewidth. enter image description here

\documentclass[]{article}
\usepackage{xcolor}
\makeatletter
\newsavebox\testbox
\def\versicle#1#2{%
  \savebox{\testbox}{\versicle@{red}{V.}~#1 \versicle@{red}{R.}~#2}
  \versicle@{red}{V.}~#1
  \ifdim\wd\testbox>\dimexpr\linewidth-\parindent\relax
    \par
  \fi
  \versicle@{red}{R.}~#2
}
\def\versicle@#1#2{\textbf{\textcolor{#1}{#2}}}
\makeatother

\begin{document}%
%This fits in one line
\versicle{Dóminus vobíscum.}{Et cum spíritu túo.}\par%
%
%This should line break at the \Rbar.
\versicle{Panem de cælo præstitísti eis, allelúia.}{Omne delectaméntum in se habéntem, allelúia.}%
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.