How to make LyX math macros available across documents?

Tobias Hilbricht hilbricht at linopus.de
Sun Aug 8 17:15:01 UTC 2021


Am Freitag, den 06.08.2021, 11:15 -0400 schrieb Paul A. Rubin:
> On 8/6/21 5:52 AM, Tobias Hilbricht wrote:
> > Dear readers of this list,
> > 
> > in my worksheets in chemistry I have to write chemical formulas and
> > physical quantities very often. But while that is very easy to do
> > in
> > LyX out of the box with chemical formulas due to the integration of
> > mhchem and its macro \ce, I am still trying to achieve something
> > similar for physical quantities with siunitx and its macro \qty.
> > 
> > What I have so far is a working LyX math macro (in LyX Ctrl+M on
> > \newcommand{\mqty}[2]{\qty{#1}{#1}}) which I can invoke with a
> > keyboard
> > shortcut (Alt+Q for "command-sequence math-insert \mqty; char-left;
> > char-left").
> > 
> > But I have to copy this custom LyX macro from document to document
> > (siunitx loaded, of course). By contrast, I can invoke the macro
> > \ce in
> > math mode with a keyboard shortcut without further ado in every
> > document and enjoy the immediate preview and avoid ERT.
> > 
> > How is it possible to have custom macros available across documents
> > in
> > the same way?
> > 
> > Thanks for helpful hints in advance!
> > 
> > Yours
> > Tobias
> > 
> >     
> > 
>  I can think of at least three possibilities.
> If you will use the custom code routinely, create a document
> containing it and make that document your new default document
> (Document > Settings ... > Save as Document Defaults.
> Create a document template that contains the custom code in its
> preamble. You just create an otherwise empty document with your
> preferred default settings and the custom code and save it in your
> local templates document. When you want to use the custom code, start
> your new document with File > New from Template ... and select the
> correct template.
> Create a module (Customization manual, section 5.2.1) containing the
> custom code, store it in your local layouts folder, and then
> reconfigure LyX so that LyX can find it. Thereafter, you can add it
> to any document using Document > Settings ... > Modules.
> Paul
> 
> 
Dear Paul and Richard,

thank you for your suggestions. I will resort to the "template
solution". This is not the same as invoking an "LyX inbuild" command
like \ce in any document, but for my purpose it is quite sufficient.

Yours 
Tobias
  



More information about the lyx-users mailing list