Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

MathMacros

Categories: Math
<< | Page list | >>

This page contains tips about Math Macros in LyX

§ Ways to enter math macros

Math-macros can be defined in three ways.

  1. The usual way is to use the graphical interface. Choose Insert->Math->Macro and type into the three boxes provided:
    • Name: The name used when inserting the macro in math. It is case sensitive, and must contain only Latin letters.
    • TeX: The actual content of the macro i.e. what gets inserted when the macro is used. Use \#1 \#2 etc to add arguments here.
    • LyX: What LyX displays when the macro is used. If blank, the TeX field is used. Useful if the TeX field doesn't look much like the final output. Note that if you have instant preview enabled for math (Tools > Preferences > Display), then LyX will only show what you put in the LyX macro box when your cursor is inside the math inset. Otherwise the final output will be shown.
  2. If you have LaTeX definition you can enter this directly as normal text and then convert it. So you can type \def\exp#1#2{#1^#2} or \renewcommand{\raise}[2]{#1^#2}, select the typed text, and type Ctrl-M to convert it to a math-macro.
  3. It can be entered into the LyX mini-buffer. Either use the mouse to put the cursor in the mini-buffer or type Meta-x. Then type: math-macro name args, where name is a string and args is an optional integer indicating the number of arguments. LyX will then open a math environment in which the macro definition can be entered. Enter arguments by typing "\#n", where n is the number of the argument.

§ Custom multi-character functions.

One-character functions in math such as f(x) should be in italics so can be entered directly into math. But multi-character functions such as sin x should be upright and have a bit of extra space, so need special treatment. Some, like sin, are predefined in LaTeX and can be accessed with commands like \sin. Note that this also includes function-like constructions like lim, sup and arg.

(LaTeX note: For technical reasons, these are sometimes called "operators" in LaTeX. In raw LaTeX you would define them with something like \DeclareMathOperator{\sgn}{sgn}.)

To declare a custom function in LyX, insert a math macro as described above, putting something like the following in the TeX part:

\operatorname{sgn}

Since LyX doesn't recognise \operatorname, you could put something like \mathrm{sgn} in the LyX part of the macro so it looks nicer when you're editing (but DON'T put this in the TeX part, because it will produce the wrong spacing).

If you are declaring a type of limit, then you will want subscripts and superscripts to be placed directly above/below it in displayed text rather than next to it. To do this use the starred variant of \operatorname in the TeX part:

\operatorname*{s-lim}

Math

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2015-04-17 21:49 UTC