This may be a LyX rather than a LaTeX thing, but here goes.
I have this snippet of code which has a macro (\TE
) within a macro (\PTV
)
$\left(\PTV[\TE[i]]\right)$
As it should, this fails with the error 'Argument of \\TE has an extra }
'. I figured out I can fix the problem by inserting a pair of curly braces around the \TE[i]
part to have
\left(\PTV[{\TE[i]}]\right)
which works just fine, until I save, close and reopen the document.
I have discovered that LyX when opening removes the braces when loading into memory (according to the 'View Source' pane). I have been doing a bit of reading around the \protect
command, but have not got it to work. I'm also not entirely convinced it is a protection issue, considering the document gets saved with the desired code (it's just reopening that is the issue).
Does anyone know what's happening? or how to force LyX to keep the braces when reading in the document? Or maybe a workaround?
EDIT: As requested, \TE
is defined:
\newcommandx\TE[1][usedefault, addprefix=\global, 1=]{\gamma_{#1}}
And \PTV
is defined:
\newcommandx\PTV[1][usedefault, addprefix=\global, 1=]{\boldsymbol{\tau}_{#1}}
EDIT2: Bug #10562 has been filed at https://www.lyx.org/trac/ticket/10562. Bug report includes a lyx file which is a minimum reproducible example of the bug.
EDIT3: I think I can now definitively say it is a bug with Lyx. Consider the following code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xargs}
\begin{document}
\newcommandx\TE[1][usedefault, addprefix=\global, 1=]{\gamma_{#1}}
\newcommandx\PTV[1][usedefault, addprefix=\global, 1=]{\boldsymbol{\tau}_{#1}}
$(\PTV[{\TE[i]}])$
\end{document}
Compiled using pdflatex in TexMaker, this compiles just fine. Import it into Lyx, and the issue I'm talking about occurs. I also note by moving the macros resolves the compilation issue in Lyx, but Lyx no longer recognises the macro (and therefore destroys one of the features of Lyx). i.e. :
\documentclass{article}
\usepackage{amsmath}
\usepackage{xargs}
\newcommandx\TE[1][usedefault, addprefix=\global, 1=]{\gamma_{#1}}
\newcommandx\PTV[1][usedefault, addprefix=\global, 1=]{\boldsymbol{\tau}_{#1}}
\begin{document}
$(\PTV[{\TE[i]}])$
\end{document}
Still not clear on why this is happening though...
\PTV
and\TE
defined? The dropping of braces sounds like a bug in LyX, so it might be worth reporting it at lyx.org/trac.\left(\PTV[\TE[i]]\right)
with\left(\PTV{\TE{i}}\right)
, i.e., if you replace the square brackets with curly braces?\TE[i]
is no longer treated as the optional argument to\PTV
.