TeX - LaTeX Asked on July 31, 2021
I am using the widetilde
macro provided by the mtpro2
package. The macro works fine in an usual paragraph, but it raises an error if used in in a section
.
MWE
documentclass{article}
usepackage[lite]{mtpro2}
begin{document}
section{$widetilde{O}$}
$widetilde{O}$
end{document}
And the error is:
! Undefined control sequence.
@widetilde ...extfont 3=MTEXE@ }else def TD@
{textfont 3=MTEXA@ }fi ...
l.6 section{$widetilde{O}$}
A similar error appears for the widehat
macro.
The commands widecheck
, widehat
and widetilde
are defined in terms of mathpalette
; precisely, widetilde
is mathpalette@widetilde
(similarly for the other two) so they should be made robust.
Not that mathpalette
is fragile by itself, but it's better if the .aux
file reports widetilde
instead of the full expansion of mathpalette@widetilde
, even if it didn't raise an error.
The method is easy
documentclass{article}
usepackage[lite]{mtpro2}
usepackage{etoolbox}
robustifywidetilde
robustifywidehat
robustifywidecheck
begin{document}
section{$widetilde{O}widehat{O}widecheck{O}$}
end{document}
The LaTeX kernel, could not make robust that many commands, because of memory limitation. So the protect
mechanism was used. In recent years, memory started to no longer be a problem and MakeRobust
was added to the kernel (instead of having to be requested with fixltx2e
).
How does a LaTeX robust command work? If one does DeclareRobustCommand{foo}[<n>]{...}
, LaTeX will define both foo
and foo•
(where •
stands for a space in the command name). The former is simply a shorthand for protectfoo•
and it's the latter that does the real work.
Until a few years ago, widetilde
was not defined as a robust command, so an input such as
documentclass{article}
usepackage[lite]{mtpro2}
MakeRobustwidetilde
was a good way to make widetilde
suitable for usage in moving arguments.
Until the LaTeX kernel made a huge step in robustifying many more commands, among which the wide math accents. Good! No need of MakeRobust
any longer!
Well, almost. Unfortunately, mtpro2
still does defwidetilde#1{...}
and this only redefines the “surface” command widetilde
, but leaves widetilde•
untouched. But now widetilde
is not robust and it will fail in moving arguments. So we apply again MakeRobustwidetilde
, isn't that easy?
Sorry, no: MakeRobust
has no way to know how a command was defined and it checks for the existence of the “inner” command (with a trailing space in its name). If it finds it, then it thinks that the command is already robust and does nothing.
So with TeX Live 2020 or later the previously suggested workaround with MakeRobustwidetilde
ceased to work.
Since robustify
uses a very different protection mechanism, one can get around the problem. Not a big deal: etoolbox
is a well-tested and maintained package.
Otherwise one has to remove the “inner version” before applying MakeRobust
.
documentclass{article}
usepackage[lite]{mtpro2}
makeatletter
newcommand{ReallyMakeRobust}[1]{%
count@ =escapechar escapechar =`
expandafterletcsnameexpandafter@gobblestring#1spaceendcsnamerelax
escapechar=count@
MakeRobust#1%
}
makeatother
ReallyMakeRobustwidetilde
ReallyMakeRobustwidehat
ReallyMakeRobustwidecheck
begin{document}
section{$widetilde{O}widehat{O}widecheck{O}$}
end{document}
Answered by egreg on July 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP