I am trying to define a new command \dfix
that can handle newlines in its arguments. The command works as expected when the arguments have no \\
in them, but LaTeX produces errors if I do include newline characters.
How can I create a command/macro that is safe with regard to line breaks?
I would like \dfix
in the following context
\begin{align*}
&\dfix{(A\\
&B)}{C}
\end{align*
to produce the same output as
\begin{align*}
&(A\\
&B)^\ddag_{C}
\end{align*}
Similarly, $\dfix{A}{B}$
should produce the same output as $A^\ddag_B$
.
Here is a MWE defining the command and trying to us it in various places.
\documentclass{minimal}
\usepackage{amsmath}
\newcommand{\dfix}[2]{\ensuremath{{#1}^\ddag_{#2}}}
\begin{document}
% This causes: ./mwe.tex:9: Missing } inserted.
\begin{align*}
&\dfix{A\\
&B}{C}
\end{align*}
% This is OK
\begin{align*}
&\dfix{A B}{C}
\end{align*}
% This also produces errors.
\begin{multline*}
\dfix{A\\
B}{C}
\end{multline*}
\end{document}
\\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)\newcommand{\dfix}[2]{\ensuremath{\begin{array}{@{}c@{}}#1\end{array}^\ddag_{#2}}}
but that still wouldn't make\dfix{A\\&B}{C}
valid syntax. What do you want\dfix
to do?align
that does not use\dfix
but makes the result you want. I can not guess from the code above,