I have a problem I'm unable to solve by myself. I need to declare a new command that would do the following:
take two pieces of text (containing also legal LaTeX commands) as arguments
check, whether placing them one after another would lead to crossing the text boundary (the right margin)
if the conditional in point 2. yields "FALSE" as its result, the two pieces of text should be placed one after another with no special action
if, however, the result of the conditional (point 2) is "TRUE", the order of the two pieces of text should be inverted.
Possibility of nesting would be a great advantage.
I need such a command to cope with non-standard typing of bidirectional text in my book. I'll be very grateful indeed if anybody helps me with this problem.
Unfortunately there's no answer yet. Perhaps provide further information, such as the code which you could produce for that until now, so a reader doesn't have to work it out from scratch.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\newlength{\rvslgth}
\newcommand\reverseif[2]{%
\settowidth{\rvslgth}{#1 #2}%
\ifdim\rvslgth>\linewidth
#2 #1%
\else
#1 #2%
\fi}
\begin{document}
% nothing:
\reverseif{First}{Second}
% reversed:
\reverseif{A longer example containing a macro (\LaTeX) and other stuff.}{This will make sure both arguments together are longer than one line.}
% nested:
\reverseif{First}{\reverseif{A longer example containing a macro (\LaTeX) and other stuff.}{This will make sure both arguments together are longer than one line.}}
\end{document}