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 http://tex.stackexchange.com/q/218121/13173 to make things clearer. – Léo Léopold Hertz 준영 Dec 15 '14 at 19:37

2 Answers2

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}
egreg
  • 1,121,712
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}
daleif
  • 54,450