As originally tweeted here, I would like to use \exp to produce some exponential expressions in math mode, but since gb4e, which I also want to use to make interlinear glossing, overwrites the command in question, I face the following error message;

! LaTeX Error: Command \item invalid in math mode.

What should I do to use \exp in math mode again, or more specifically, how should I avoid the conflict of \exp in math mode and that of gb4e?

I'm using RMarkdown with XeLaTeX, so I put a MWE as a .Rmd file style.

Original MWE

documentclass: bxjsarticle  
classoption: pandoc,everyparhook=compat
    latex_engine: xelatex
    keep_tex: true
  - \makeatletter 
  - \def\new@fontshape{}
  - \makeatother
  - \usepackage{gb4e}\noautomath
title: "Example"

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.


MWE (.tex ver.)

\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\else % if luatex or xelatex
% use upquote if available, for straight quotes in verbatim environments
% use microtype if available
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
            pdfborder={0 0 0},
\urlstyle{same}  % don't use monospace font for urls
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
}{% else
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
% Redefines (sub)paragraphs to behave more like sections

%%% Use protect on footnotes to avoid problems with footnotes in titles

%%% Change title format to be more compact

% Create subtitle command for use in maketitle






Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.



Try and Error

Following an answer to avoid name conflict, I have tried to redefined \exp, but in vain.


I have never used gb4e, but looking at its definition of \exp

% gb4e.sty line 319

I'd say the following should work (hoping that I made a meaningful MWE for gb4e)


\let\mathexp=\exp % save the current (math) definition of \exp
\let\gbexp=\exp % save the current (gb4e) definition of \exp




\ex\label{here} Bar foo baz.
\exp{here}{Foo bar baz.}


enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.