Math Macro's In LyX
Udicoudco
udifoglle at gmail.com
Thu Sep 1 00:27:33 UTC 2022
Hello LyX Developers,
Currently (or at least in LyX 2.3.6.1) the definition of a new math macro
with LyX's GUI is implemented using a latex code of the form
\global\long\def\foo#1{<definition>}
I'm guessing this is implemented this way because you can never be sure if
a user will define the macro within a group without knowing.
Since \def is not checking if the command name is already taken, it could
cause some problems if a user that is unfamiliar with some LaTeX (or even
TeX) commands will override them unknowingly (some of my colleagues at the
university had this problem).
In this situation, the log file is not very helpful, and it is inconvenient
to debug the file. If the implementation was via \newcommand, there was a
clear error massege "Command \foo already defined.", but the problem is the
\global\newcommand is not making the macro assignment global.
Using \globaldefs (see page 275 in The TeX Book, or here
<https://en.wikibooks.org/wiki/TeX/globaldefs>) we might get a global
assignment with \newcommand. First we can define a new command fo the
matter (LyX may include this line in the preamble if it notices a math
macro defintion was done via the GUI):
\newcommand{\lyxnewcommand}[3][0]{\bgroup\globaldefs=1\newcommand{#2}[#1]{#3}\egroup}
and then, if for example i would like to define a new math macro named \foo
with 2 parameters via the GUI, LyX will write the following line:
\lyxnewcommand[3]{\foo}{<definition of \foo>}
Hope you will consider this suggestion as I was facing this problem (while
debugging other people's files) a bunch of times.
If there is another reason the implementation was made via \def that i did
not consider, I will be happy to hear about that.
Best Regards,
Udi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20220901/a9d6749c/attachment.html>
More information about the lyx-devel
mailing list