我可以在背面切換我使用的編譯器。我正在製作海報,需要使用 LuaLatex 作為編譯器。但是,「\DeclareUnicodeCharacter{2212}{-}」行會導致「未定義的控制序列」錯誤。
我將舉一個例子來說明我的觀點。
\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}
當我選擇“pdfLatex”編譯器時它編譯得很好,但當我使用“LuaLatex”編譯器時它會崩潰。是否有可以用於 LuaLatex 編譯器的替代行(到 \DeclareUnicodeCharacter{2212}{-})?謝謝。
答案1
我建議您修改序言,以便您可以使用 pdfLaTeX 或 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}
透過此設置,僅在使用 pdfLaTeX 編譯文件時才會載入inputenc
和套件。fontenc
旁白:由於mathtools
套件會自動加載amsmath
,因此無需amsmath
單獨加載。 (並且,對於該類beamer
,amsmath
預設會載入套件......)
答案2
您可以newunicodechar
在任何引擎中使用該套件:
\usepackage{newunicodechar}
\newunicodechar{−}{-} % U+2212
然而,如果你想在 LuaLaTeX 中使用 Unicode 輸入,你最好unicode-math
使用professionalfonts
.beamer