2

I am on overleaf where I can switch the compiler that I use. I am working on a poster and require the use of LuaLatex as a compiler. However, the line "\DeclareUnicodeCharacter{2212}{-}" causes "undefined control sequence" error.

I will give an example to illustrate my point.

\documentclass[pt]{beamer}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{upgreek}
\usepackage{mathtools}
\usetheme{Berlin}

\DeclareUnicodeCharacter{2212}{-}

\begin{document}
\begin{frame}{Example}
    The equation is
    \begin{equation}
    y=mx+c
    \end{equation}
\end{frame}
\end{document}

It compiles fine when I choose the "pdfLatex" compiler but breaks when I use the "LuaLatex" compiler. Is there an alternative line (to \DeclareUnicodeCharacter{2212}{-}) that I can use for the LuaLatex compiler? Thanks.

5
  • 3
    For LuaLaTeX, don't load the inputenc and fontenc packages; instead, load the fontspec package.
    – Mico
    Commented May 1 at 8:41
  • @MIcro, thanks. So just replace the line \usepackage[utf8]{inputenc} with \usepackage[utf8]{fontspec}? I tried it but still doesn't work. Can you show me the changes to my code above? You can type it as an answer and I can accept it.
    – Resu
    Commented May 1 at 8:44
  • 1
    DeclareUnicodeCharacter sets up inputenc to map the byte seqence for 2212 it is not defined for luatex you can just use the character directly Commented May 1 at 8:50
  • 1
    Please see the answer I posted. By the way, utf8 has been the default option for the inputenc package for several years now. (BTW, it's "Mico", not "Micro"...)
    – Mico
    Commented May 1 at 8:52
  • 1

2 Answers 2

4

I suggest you modify your preamble so that you can potentially compile the document with either pdfLaTeX or LuaLaTeX.

\documentclass[pt]{beamer}
\usetheme{Berlin}
\usepackage[brazil]{babel}

\usepackage{iftex} % for '\iftutex' and related conditionals
\iftutex
   \usepackage{fontspec} % optional
\else
   \usepackage[T1]{fontenc}
   %\usepackage[utf8]{inputenc} % 'utf8' is the default nowadays
   \DeclareUnicodeCharacter{2212}{-}
   \usepackage{upgreek}
\fi

\usepackage{mathtools} % no need to load 'amsmath' separately

\begin{document}
\begin{frame}{Example}
    The equation is
    \begin{equation}
    y=mx-c
    \end{equation}
\end{frame}
\end{document}

With this setup, the inputenc and fontenc packages are loaded only if pdfLaTeX is used to compile the document.

Aside: Since the mathtools package loads amsmath automatically, there's no need to load amsmath separately. (And, with the beamer class, amsmath package is loaded by default...)

2
  • 1
    might be better to use \iftutex rather than \ifpdflatex then latex and ptex as well as pdflatex would take the right branch Commented May 1 at 8:55
  • 1
    @DavidCarlisle - Great idea. :-) Let me fix that right away.
    – Mico
    Commented May 1 at 8:56
4

You can use the newunicodechar package in any engine:

\usepackage{newunicodechar}

\newunicodechar{−}{-} % U+2212

However, if you want to use Unicode input in LuaLaTeX, you are probably better off loading unicode-math with the professionalfonts option of beamer.

2
  • 2
    you can use newunicodechar in any engine but not ^^^^ so a cross engine version would be \newunicodechar{−}{-} Commented May 1 at 9:40
  • 1
    @DavidCarlisle Good point. Edited.
    – Davislor
    Commented May 1 at 12:04

You must log in to answer this question.

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