I am using LyX and I tried adding a macro that includes TeX code but it seems as if it doesn't recognize the \abs command:

enter image description here

To be clarified, when adding the following TeX code the file compiles:

enter image description here

and the absolute value is presented correctly in the exported pdf file:

enter image description here

Any help would be appreciated.

  • Probably you define the \abs command in the preamble? If so, LyX does not know about it. If you don't define it in the preamble or in ERT, please post a minimal example .lyx file.
    – scottkosty
    Mar 25, 2019 at 17:29
  • Indeed, I defined it the preamble. In general I'm looking for a way to add this command to LyX so that I can use it in a math box. Mar 26, 2019 at 17:33

1 Answer 1


It would appear from the way that LyX stores macros (as relative to a document) that the basic declaration is needed in the preamble before the math macro can be defined.

enter image description here

%% LyX 2.3.2-2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
        \setlength{\listparindent}{0pt}% needed for AMS classes

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.



% GlobalLongDef is the standard method LyX uses to store macros
% Here definition of HW for ABS is thus a simple substitution 
% NOTE in the following that \HW* behaves exactly like \ABS*

~Hello~World~the~result~of~$\left|\frac{A}{X^{2}+Y^{2}}\right|$~in~LyX,~in~\textrm{\textbf{${\normalcolor T}_{E}^{X}$}}~is~${\HW*{\frac{A}{X^2+Y^2}}}$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .