Wie kann ich die Schriftart \boldmath mit Unicode-Mathematik einstellen?

Wie kann ich die Schriftart \boldmath mit Unicode-Mathematik einstellen?

Ich versuche, ein Dokument in Linux Libertine zu setzen, und ich möchte die Schriftart auch für alphanumerische Zeichen im Mathematikmodus verwenden. Ich verwende unicode-math, nicht mathspec, weil ich Alphabete wie explizit angeben muss, mathupum die Kompatibilität mit Paketen wie sicherzustellen hepnames. Ich habe keine Möglichkeit gefunden, dies mit zu tun mathspec. Die von mir verwendete Engine ist XeLaTeX. Ich gebe zunächst TeX Gyre Pagella Math als vollständige Mathematikschriftart für Symbole usw. an. Ich möchte, dass die nachfolgenden Deklarationen die Schriftart für Textzeichen als Libertine überschreiben.

Ich finde mehrere Probleme, die im folgenden MWE veranschaulicht werden:

  1. Der \boldmathSchalter bewirkt nichts.
  2. Zahlen werden in Fett- und Kursivschrift nicht korrekt wiedergegeben, nur Buchstaben.
  3. \mathbf(das letzte „A = 1“ im MWE) wird in Pagella wiedergegeben, in Libertine überhaupt nicht.

Ich habe bereits versucht, /{latin,Latin,num}die rangeDeklarationen zu ergänzen, ohne Erfolg. Was übersehe ich hier?

\documentclass{minimal}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont[%
    Ligatures=TeX,
    BoldFont=LinLibertine_RB.otf,
    ItalicFont=LinLibertine_RI.otf,
    BoldItalicFont=LinLibertine_RBI.otf]
    {LinLibertine_R.otf}

\setmathfont{texgyrepagella-math.otf}

\setmathfont[range=\mathup]{LinLibertine_R.otf}
\setmathfont[range=\mathbf]{LinLibertine_RB.otf}
\setmathfont[range=\mathit]{LinLibertine_RI.otf}
\setmathfont[range=\mathbfit]{LinLibertine_RBI.otf}

\begin{document}
    \begin{tabular}{lll}
        Text     & A = 1               & \textit{B = 2}\\
        Textbf   & \textbf{A = 1}      & \textbf{\textit{B = 2}}\\
        Math     & $A = 1$             & $\mathit{B = 2}$\\
        Boldmath & {\boldmath $A = 1$} & {\boldmath $\mathit{B = 2}$}\\
        Mathbf   & $\mathbf{A = 1}$    & $\mathbfit{B = 2}$\\
    \end{tabular}
\end{document}

Bildbeschreibung hier eingeben

Ohne Schriftartänderungen sieht alles ok aus:

\documentclass{minimal}

\begin{document}
    \begin{tabular}{lll}
        Text     & A = 1               & \textit{B = 2}\\
        Textbf   & \textbf{A = 1}      & \textbf{\textit{B = 2}}\\
        Math     & $A = 1$             & $\mathit{B = 2}$\\
        Boldmath & {\boldmath $A = 1$} & {\boldmath $\mathit{B = 2}$}\\
    \end{tabular}
\end{document}

Bildbeschreibung hier eingeben

Antwort1

Ich habe eine Lösung gefunden, die für mich funktioniert. Ich habe angefangen, damit herumzuspielenversion=bold , wie David vorgeschlagen hat, aber das hat sich immer wieder geändertallemein Text im Mathematikmodus fett. Am Ende bin ich von Dateinamen auf Systemschriftnamen umgestiegen. (Das wollte ich zunächst vermeiden, da ich von mehreren verschiedenen Rechnern aus an demselben Dokument arbeite.) Mit Systemschriftnamen \boldmath hat es sofort und automatisch funktioniert. Ich habe auch festgestellt, dass \mathbfupanstelle von angegeben werden muss \mathbf.

Ein weiteres Problem bei der Verwendung von Systemschriftartennamen besteht darin, dass der halbfette Libertine-Stil aus irgendeinem Grund standardmäßig als fett geladen wird. Dies ist der Grund für die BoldFontSpezifikation im folgenden MWE.

Die Lösung ist nicht perfekt. Sie können sehen, dass alle Zahlen im Mathematikmodus aufrecht dargestellt werden, sogar in \mathit. Außerdem ist die Zahl in \mathbfitnicht fett. Alle Schriftarten sind jedoch korrekt und für meine Zwecke ist es gut genug.

\documentclass{minimal}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont[
    BoldFont=Linux Libertine Bold,
    BoldItalicFont=Linux Libertine Bold Italic]
    {Linux Libertine}

\setmathfont{TeX Gyre Pagella Math}

\setmathfont[range=\mathup,
    BoldFont=Linux Libertine Bold,
    BoldItalicFont=Linux Libertine Bold Italic]
    {Linux Libertine}
\setmathfont[range=\mathit,
    BoldFont=Linux Libertine Bold Italic]
    {Linux Libertine Italic}
\setmathfont[range=\mathbfup]{Linux Libertine Bold}
\setmathfont[range=\mathbfit]{Linux Libertine Bold Italic}

\begin{document}
    \begin{tabular}{lll}
        ~        &\ Regular             &\ Italic\\
        Text     &\ A = 1               &\ \textit{A = 1}\\
        Textbf   &\ \textbf{A = 1}      &\ \textbf{\textit{A = 1}}\\
        Math     &\ $A = 1$             &\ $\mathit{A = 1}$\\
        Boldmath &\ {\boldmath $A = 1$} &\ {\boldmath $\mathit{A = 1}$}\\
        Mathbf   &\ $\mathbf{A = 1}$    &\ $\mathbfit{A = 1}$\\
    \end{tabular}
\end{document}

Bildbeschreibung hier eingeben

Antwort2

tg85 bemerktezwei Probleme mit der Antwort, die er auf seine eigene Frage gegeben hat:

Die Lösung ist nicht perfekt. Sie können sehen, dass alle Zahlen im Mathematikmodus aufrecht dargestellt werden, sogar in \mathit. Außerdem ist die Zahl in \mathbfitnicht fett. Alle Schriftarten sind jedoch korrekt und für meine Zwecke ist es gut genug.

DerUnicode-MathematikHandbuch(Abbildung 7) besagt, dass die aufrechte Form für Ziffern tatsächlich absichtlich gewählt wurde, da sie „auch im Kursivstil immer aus der aufrechten Schriftart übernommen werden sollten“. In Übereinstimmung mit dieser Aussage scheint Unicode keine Slots für kursive Ziffern zu definieren – während es Slots für fette Ziffern, serifenlose Ziffern usw. definiert. Siehehttps://en.wikipedia.org/wiki/Mathematical_Operators_and_Symbols_in_Unicode#Mathematical_Alphanumeric_Symbols_block.

Ich kann jedoch verstehen, dass man sich dennoch wünscht, dass der Satz vonUnicode-Mathematikum mit dem ursprünglichen LaTeX-basierten Schriftsatz konsistent zu sein, wobei\mathit{1} eine kursive Ziffer Eins erzeugt wird. Daher, inspiriert vonCode von tg85habe ich eine Lösung gefunden, die diese beiden Probleme behebt (funktioniert auch mit LuaLaTeX):

% !TEX program = xelatex


\documentclass{minimal}


\usepackage{ifthen}
\usepackage[svgnames]{xcolor}

\usepackage[
   mathit = sym, mathup = sym, mathbf = sym,
   math-style = ISO, bold-style = ISO
]{unicode-math}

\setmainfont{LinLibertine_R.otf}[
   ItalicFont = LinLibertine_RI.otf,
   BoldFont = LinLibertine_RB.otf,
   BoldItalicFont = LinLibertine_RBI.otf
]
\setmonofont{FiraMono-Medium.otf}[
   Scale = 0.81,
   Color = DarkBlue
]

\setmathfont{XITSMath-Regular.otf}[
   BoldFont = XITSMath-Bold.otf
]
\setmathfont{XITSMath-Regular.otf}[
   version = mathitVersion
]
\setmathfont{XITSMath-Regular.otf}[
   version = mathbfitVersion
]
\setmathfont{XITSMath-Bold.otf}[
   version = boldmathVersion
]

\setmathfont{LinLibertine_R.otf}[
   range = up/{num, latin, Latin, greek, Greek},
   BoldFont = LinLibertine_RB.otf
]
\setmathfont{LinLibertine_RI.otf}[
   range = it/{num, latin, Latin, greek, Greek},
   BoldFont = LinLibertine_RBI.otf,
   NFSSFamily = mathitalic
]
\setmathfont{LinLibertine_RBI.otf}[
   range = bfit/{latin, Latin, greek, Greek},
   NFSSFamily = mathbolditalic
]
\setmathfont{LinLibertine_RB.otf}[
   range = bfup/{num, latin, Latin, greek, Greek}
]

\newif \ifBoldMath \BoldMathfalse
\let \mathversionorig \mathversion
\renewcommand{\mathversion}[1]{%
   \ifthenelse{\equal{#1}{bold}}{%
      \BoldMathtrue%
   }{%
      \BoldMathfalse%
   }%
   \mathversionorig{#1}%
}

\AtBeginDocument{%
   \let \mathitorig \mathit%
   \renewcommand{\mathit}[1]{%
      \ifBoldMath%
         \textbf{%
            \SetSymbolFont{__um_fam1}{boldmathVersion}{TU}{mathbolditalic}{b}{it}%
            \SetSymbolFont{__um_fam2}{boldmathVersion}{TU}{mathbolditalic}{b}{it}%
            \mathversion{boldmathVersion}%
            \(\mathitorig{#1}\)%
         }
      \else%
         \textit{%
            \SetSymbolFont{__um_fam1}{mathitVersion}{TU}{mathitalic}{m}{it}%
            \mathversion{mathitVersion}%
            \(\mathitorig{#1}\)%
         }%
      \fi%
   }%
   \let \mathbfitorig \mathbfit%
   \renewcommand{\mathbfit}[1]{{%
      \textbf{%
          \SetSymbolFont{__um_fam1}{mathbfitVersion}{TU}{mathbolditalic}{b}{it}%
          \mathversion{mathbfitVersion}%
          \(\mathbfitorig{#1}\)%
      }%
   }}%
}

\newcommand{\testUnicodeMath}{%
   \bigskip
   \begin{tabular}{l @{\quad}l @{\quad} l @{\quad} l @{\quad} l}
       Row
       & Math version/alphabet
       & Regular
       & Upright
       & Italic \\[\medskipamount]
       1
       & Text
       & A = 1a
       & \textup{B = 2b}
       & \textit{C = 3c} \\
       2 &
       \texttt{\textbackslash textbf}
       & \textbf{A = 1a}
       & \textbf{\textup{B = 2b}}
       & \textbf{\textit{C = 3c}} \\
       3
       & \texttt{\textbackslash mathversion\{normal\}} (default)
       & $A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}$
       & $\mathup{B = 2b + \beta \times \Gamma}$
       & $\mathit{C = 3c + \beta \times \Gamma}$ \\
       4
       & \texttt{\textbackslash mathversion\{bold\}}/\texttt{\textbackslash boldmath}
       & \boldmath $A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}$
       & \boldmath $\mathup{B = 2b + \beta \times \Gamma}$
       & \boldmath $\mathit{C = 3c + \beta \times \Gamma}$ \\
       5
       & \texttt{\textbackslash mathbf}/\texttt{\textbackslash mathbfup}/\texttt{\textbackslash mathbfit}
       & $\mathbf{A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}}$
       & $\mathbfup{B = 2b + \beta \times \Gamma}$
       & $\mathbfit{C = 3c + \beta \times \Gamma}$ \\
   \end{tabular}%
   \bigskip
   \bigskip
}


\begin{document}

\testUnicodeMath

\textit{Check that everything works properly by invoking it a~second time:}

\testUnicodeMath

\textit{Check that everything works properly by invoking it a~third time:}

\testUnicodeMath

\end{document}

Das Ergebnis ist die folgende Ausgabe (beachten Sie, dass die „3“ in der dritten Tabellenzeile nun kursiv und in den Zeilen 4 und 5 fett kursiv gedruckt ist):

\mathit und \mathbfit behoben

Beachten Sie auch den Kontrast zwischen \mathversion{bold}/ \boldmathund \mathbf/ \mathbfup/ \mathbfit: Ersteres macht auch alle Operatoren, Integrale usw. fett, während letzteres nur Buchstaben und Ziffern betrifft.

Antwort3

Die Verwendung des Pakets amsbsy und \pmb scheint das Boldmath zu erhalten.

\documentclass{minimal}

\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{amsbsy}

\setmainfont[%
Ligatures=TeX,
BoldFont=LinLibertine_RB.otf,
ItalicFont=LinLibertine_RI.otf,
BoldItalicFont=LinLibertine_RBI.otf]
{LinLibertine_R.otf}

\setmathfont{texgyrepagella-math.otf}

\setmathfont[range=\mathup]{LinLibertine_R.otf}
\setmathfont[range=\mathbf]{LinLibertine_RB.otf}
\setmathfont[range=\mathit]{LinLibertine_RI.otf}
\setmathfont[range=\mathbfit]{LinLibertine_RBI.otf}

\begin{document}
\begin{tabular}{lll}
    Text     & A = 1               & \textit{B = 2}\\
    Textbf   & \textbf{A = 1}      & \textbf{\textit{B = 2}}\\
    Math     & $A = 1$             & $\mathit{B = 2}$\\
    Boldmath & { $\pmb{A = 1}$} & {$\pmb{\mathit{B = 2}}$}\\
    Mathbf   & $\mathbf{A = 1}$    & $\mathbfit{B = 2}$\\
\end{tabular}
\end{document}

Bildbeschreibung hier eingeben

Antwort4

Mit xelatexoderlualatex

\documentclass{standalone}
\usepackage{hepparticles}
\usepackage{hepnames}
\usepackage[math-style=ISO]{unicode-math}
\usepackage{libertinus}
\usepackage{array}
\begin{document}

\tabcolsep=10pt
    \begin{tabular}{>{\ttfamily\textbackslash}lll}
    normalfont & Regular           &\itshape Italic\\
    textnormal & A = 1             & \textit{A = 1}\\
    textbf     & \textbf{A = 1}    & \textbf{\textit{A = 1}}\\
    mathup     & $\mathup{A} = 1$  & $A = 1$\\
    symbf      & $\symbfup{A = 1}$ & $\symbfit{A = 1}$\\
    mathbf     & $\mathbf{A = 1}$  & $\mathbfit{A = 1}$\\
\end{tabular}

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen