The \underbar macro is a text mode macro that can also be used
in math mode. However, when inserting it in mathed, LyX helpfully
wraps it in a \text inset. One can dissolve such text inset and
the macro would appear in math mode without any problem. But the
output routine thinks that the user is shooting itself in the
foot and tries to protect him by wrapping \underbar in the
\lyxmathsym macro, whose definition is normally added to the
preamble when an unicode character is used in math mode.

Of course, this is not the case for \underbar and a compile
error arises. The easier solution is to simply add lyxmathsym as
a requirement for \underbar in lib/symbols, but this means
that the definition of \lyxmathsym would be added even when not
necessary (because in the validation routine we miss the info
about the current mode). The correct solution is acknowledging
the dual nature of \underbar as a text-mode macro that can also
be used in math mode. Luckily the correct solution is almost as
easy as the easier one and is what is done in this commit.
This commit is contained in:
Enrico Forestieri 2023-11-08 23:59:43 +01:00
parent 53784b90ae
commit 039de52ad9
2 changed files with 3 additions and 2 deletions

View File

@ -58,7 +58,7 @@ overline decoration none
overrightarrow decoration none
tilde decoration none
uline decoration none ulem
underbar decoration none
underbar decoration everymode
underbrace decoration none
underleftarrow decoration none amsmath
underleftrightarrow decoration none amsmath

View File

@ -182,7 +182,8 @@ void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
void InsetMathDecoration::write(TeXMathStream & os) const
{
bool needs_mathmode = currentMode() == MATH_MODE;
bool textmode_macro = currentMode() == TEXT_MODE;
bool textmode_macro = currentMode() == TEXT_MODE
&& key_->extra != "everymode";
MathEnsurer ensurer(os, needs_mathmode, true, textmode_macro);
if (os.fragile() && protect())
os << "\\protect";