2

I am converting my codes from pdflatex to XeLaTeX

Minimal case

\documentclass{article}
\usepackage{polyglossia} % also loads package fontspec
\setmainfont{Minion Pro} % or whatever OTF you have on your system
\setmainlanguage{english} % loads language hyphenation rules and such
\usepackage{unicode-math} % if you also need maths
\setmathfont{Cambria Math} % or whatever math OTF you have on your 
% Problem with these declarations which I like to use
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\begin{equation}
\norm{x} + \abs{y} = 1
\end{equation}
\end{document}

where I had previously

% \usepackage{amsmath, amsfonts, amssymb, textcomp, mathtools, xparse}
% \usepackage[T4, OT1]{fontenc}

What is the correct way of having these declarations in XeLaTeX?

Some challenges with Egreg's approach

Example data

\begin{equation}
\norm{x} + \abs{y} = 1 is \norm{x} + \abs{y} = 1 \square.
\end{equation}

I can resolve these errors by this

\usepackage{mathtools, xparse} % load mathtools before loading fontspec
% amsmath never needed with mathtools
\usepackage{amsfonts, amssymb, textcomp} % not sure if these are necessary
% https://tex.stackexchange.com/a/213430/13173
\usepackage{polyglossia} % also loads package fontspec
\setmainfont{Minion Pro} % or whatever OTF you have on your system
\setmainlanguage{english} % loads language hyphenation rules and such
\usepackage{unicode-math} % if you also need maths
\setmathfont{Cambria Math} % or whatever math OTF you have on your system

where I cannot understand which is the critical package. I think xparse is needed but it does not solve the square-symbol -challenge when used this package with Egreg's code.

  • 1
    fontenc you don't need, amsmath you never needed if you load mathtools, so you should just be able to load mathtools and xparse as before. did you get any specific errors with them? – David Carlisle Nov 22 '14 at 17:53
  • 3
    Since \DeclarePairedDelimiter is provided by mathtools, you have to load it. Put it before loading fontspec. But, please, do some research before asking questions. – egreg Nov 22 '14 at 17:53
  • @egreg Thank you for your comment which is also a right answer! I will study this issue more, since now, I have a need for good typography. – Léo Léopold Hertz 준영 Nov 22 '14 at 20:06
  • @Masi, please cite the errors as well. Hard to debug when one does not have the specific fonts. – daleif Dec 15 '14 at 19:06
  • I moved the other problem to this discussion tex.stackexchange.com/q/218121/13173 to make things clearer. – Léo Léopold Hertz 준영 Dec 15 '14 at 19:37
3

The command \DeclarePairedDelimiter is defined by mathtools. Since this package also loads amsmath it must go before fontspec:

\documentclass{article}

\usepackage{mathtools}
\usepackage{polyglossia} % also loads package fontspec
\usepackage{unicode-math} % if you also need maths

\setmainlanguage{english} % loads language hyphenation rules and such

\setmainfont{Minion Pro} % or whatever OTF you have on your system
\setmathfont{Cambria Math} % or whatever math OTF you have on your 

% Problem with these declarations which I like to use
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}

\begin{equation}
\norm{x} + \abs{y} = 1
\end{equation}

\end{document}
  • Let's assume this line \norm{x} + \abs{y} = 1 is \norm{x} + \abs{y} = 1 \square. Which package you need for this symbol? – Léo Léopold Hertz 준영 Dec 15 '14 at 18:18
  • This is strange. Mathtools should load amsmath which should have \square -symbol. – Léo Léopold Hertz 준영 Dec 15 '14 at 18:29
  • @Masi, no, there are TWO AMS packages, mathtools only load amsmath, extra symbols are loaded via amssymb. Usually you load both – daleif Dec 15 '14 at 18:37
  • 1
    @masi, then please update your questing with the log of that error. I do not have any of the fonts used here, but loading amssymb alongside mathtools and commenting out the two \setm... font loading macros, then \square works just fine for me. – daleif Dec 15 '14 at 18:48
  • 1
    @Masi U+25A1 WHITE SQUARE; in unicode-math it is \mdlgwhtsquare; or U+25AB WHITE SMALL SQUARE called \smwhtsquare – egreg Dec 15 '14 at 23:25
2

In relation to the extra question about \square. I do not have Minion Pro, but out commenting the two \setm... font lines and adding amssymb, then this compiles just fine using xelatex

\documentclass{article}

\usepackage{mathtools,amssymb}
\usepackage{polyglossia} % also loads package fontspec
\usepackage{unicode-math} % if you also need maths

\setmainlanguage{english} % loads language hyphenation rules and such

%\setmainfont{Minion Pro} % or whatever OTF you have on your system
%\setmathfont{Cambria Math} % or whatever math OTF you have on your 

% Problem with these declarations which I like to use
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}

\begin{equation}
\norm{x} + \abs{y} = 1 \square
\end{equation}

\end{document}
  • You are right! This works for the square! I am now thinking the other case where math in the section's title. – Léo Léopold Hertz 준영 Dec 15 '14 at 19:25
  • That also work in this example. Now you see why we ask for the error messages or the entire log file? – daleif Dec 15 '14 at 19:31
  • This one \section{Complex pathogenesis $\to$ complicated classification} ? – Léo Léopold Hertz 준영 Dec 15 '14 at 19:38
  • Compiles just fine. Please update your question with the contents of the .log file. – daleif Dec 15 '14 at 19:40
  • Yes, I did so. Log is here tex.stackexchange.com/q/218121/13173 – Léo Léopold Hertz 준영 Dec 15 '14 at 19:45

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.