If you're interested in that particular syntax, the following might be of interest:
\documentclass{article}
\makeatletter
\def\dual#1{\expandafter\dual@aux#1\@nil}
\def\dual@aux#1/#2\@nil{\begin{tabular}{@{}c@{}}#1\\#2\end{tabular}}
\makeatother
\begin{document}
If you walk \dual{left/right}, you will see a \dual{house/boat} with \dual{an old man/a cat}.
\end{document}
It uses the parameter text of a \def
inition to specify the required input: \dual{<top>/<bottom>}
. If you wish to have a different layout (not vertically centred), try using \begin{tabular}[t]
:
or \begin{tabular}[b]
:
Here is an expansion of the above solution that provides some key-value options:
\documentclass{article}
\usepackage{xkeyval}% http://ctan.org/pkg/xkeyval
\makeatletter
\newlength{\dk@toplen}\newlength{\dk@botlen}
\define@cmdkey{dualkey}[dk@]{halign}[c]{}%
\define@cmdkey{dualkey}[dk@]{valign}[c]{}%
\define@key{dualkey}{topwidth}{\setlength{\dk@toplen}{#1}}
\define@key{dualkey}{botwidth}{\setlength{\dk@botlen}{#1}}
\newcommand{\dual}[2][,]{% \dual[<opts>]{<top>/<bot>}
\setkeys{dualkey}{valign=c,halign=c,topwidth=\m@ne\p@,botwidth=\m@ne\p@,#1}% Set (default) keys
\expandafter\dual@aux#2\@nil}% Print dual
\def\dual@aux#1/#2\@nil{%
\begin{tabular}[\dk@valign]{@{}\dk@halign @{}}
\ifdim\dk@toplen<\z@ #1\else\makebox[\dk@toplen]{#1}\fi\\
\ifdim\dk@botlen<\z@ #2\else\makebox[\dk@botlen]{#2}\fi
\end{tabular}}
\makeatother
\begin{document}
If you walk \dual[valign=b]{left/right}, you will see a \dual[valign=b,topwidth=0pt]{house/boat} with
\dual[valign=t,halign=r]{an old man/a cat}.
\end{document}
You can now set the vertical and horizontal alignment within \dual
(default is c
enter for both), as well as the width of the respective items. This allows for a better flow of the sentence structure, if need be. Line-breaking at the end of the text block will still be problematic though, due to the boxing nature of \dual
.