1

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.

2
  • 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

0

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.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\newenvironment{lyxcode}
    {\par\begin{list}{}{
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\listparindent}{0pt}% needed for AMS classes
        \raggedright
        \setlength{\itemsep}{0pt}
        \setlength{\parsep}{0pt}
        \normalfont\ttfamily}%
     \item[]}
    {\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\makeatother

\usepackage{babel}
\begin{document}

\begin{lyxcode}
\global\long\def\HW{\abs}% 
% 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}}}$
\end{lyxcode}

\end{document}

You must log in to answer this question.

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