1

I am managing a XeLaTeX template for editing my own books, which, under mathspec, allows me to pick some font families in my catalog and use them in the document.

Unfortunately, since frequently the discussion treats math equations as part of the text instead of formulas being shown, I want to take the main punctuation symbols of the text font (,, ., ; and :) and use them in the math mode.

The fonts used for text and for math are different and, the farthest I've done is to take one of the math fonts subsets (Digits, Latin or Greek) to use the punctuation, but none of these font sets used for math mode has the same punctuation symbols used in text mode.

Sorry for including all the packages I normally use, but trying to remove some of them I think are unnecessary to provide a MWE gave me some random errors.

\documentclass[a4paper,12pt,twoside]{book}

\usepackage{indentfirst}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{fdsymbol}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{longtable}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{paralist}
\usepackage{enumitem}
\usepackage{titleps}
\usepackage{mathspec}
\usepackage{polyglossia}
\usepackage{geometry}
\usepackage{lipsum}

\setdefaultlanguage{brazil}
\geometry{a5paper, left=2.000cm, right=2.000cm, top=2.800cm, bottom=2.800cm}
\defaultfontfeatures{Scale=MatchLowercase,Ligatures=TeX}

% ?

\XeTeXinterchartokenstate=1

% Declaring Font Families

\newfontfamily{\setpunctfont}[
    Path            = ./fonts/text/ ,
    UprightFont     = regular.otf ,
    BoldFont        = regular.otf ,
    ItalicFont      = regular.otf ,
    BoldItalicFont  = regular.otf ,
    Scale           = MatchLowercase ,
    NFSSFamily      = puncty
    ]{jPunct}

\setmainfont[
    Path            = ./fonts/text/ ,
    UprightFont     = regular.otf ,
    BoldFont        = bold.otf ,
    ItalicFont      = italic.otf ,
    BoldItalicFont  = bold-italic.otf ,
    Scale           = MatchLowercase
    ]{jMain}

\setmathfont(Latin)[
    Path            = ./fonts/math/ ,
    UprightFont     = latin.otf ,
    BoldFont        = latin.otf ,
    ItalicFont      = latin.otf ,
    BoldItalicFont  = latin.otf ,
    Scale           = MatchLowercase
    ]{jMathLatin}

% ?

\makeatletter
    \ifx\e@alloc@intercharclass@top\@undefined
        \chardef\CharBound=255
    \else
        \chardef\CharBound=\e@alloc@intercharclass@top
    \fi
\makeatother

\chardef\CharBase=0
\newXeTeXintercharclass\CharPcts
\XeTeXcharclass"002C=\CharPcts
\XeTeXcharclass"002E=\CharPcts
\XeTeXcharclass"003A=\CharPcts
\XeTeXcharclass"003B=\CharPcts
\newtoks\TokenPunctFont
\TokenPunctFont={\begingroup\setpunctfont}
\XeTeXinterchartoks\CharBase\CharPcts=\TokenPunctFont
\XeTeXinterchartoks\CharBound\CharPcts=\TokenPunctFont
\XeTeXinterchartoks\CharPcts\CharBase={\normalfont\endgroup}
\XeTeXinterchartoks\CharPcts\CharBound={\normalfont\endgroup}

\DeclareSymbolFont{PunctSymb}{TU}{puncty}{m}{n}
\Umathchardef\MathPunctComma="3 \symPunctSymb "002C
\Umathchardef\MathPunctDot="3 \symPunctSymb "002E
\Umathchardef\MathPunctSemiColon="3 \symPunctSymb "003B
\Umathchardef\MathPunctColon="3 \symPunctSymb "003A

\begin{document}

    ASP.<> $ASP.;,:<>$ \textbf{A.B,C} \textit{A,B;C.}.  $\MathPunctDot$.

\end{document}

So, I want math . to correspond to \MathPunctDot and I can fix properly the another three punctuation symbols.

0

Through XeLaTeX documentation, you can use, instead of \Umathchardef, the command \Umathcode. Since you want to change the punctuation symbols to keep them like text mode, then you can set up the following:

  1. You do not need a separate font family for punctuation. Declare NFSSFamily for your main font instead.

    \setmainfont[
        Path            = ./fonts/text/ ,
        UprightFont     = regular.otf ,
        BoldFont        = bold.otf ,
        ItalicFont      = italic.otf ,
        BoldItalicFont  = bold-italic.otf ,
        Scale           = MatchLowercase ,
        NFSSFamily      = puncty
    ]{jMain}
    
  2. The declaration

    \DeclareSymbolFont{PunctSymb}{TU}{puncty}{m}{n}
    

    now handles directly your main font. You can declare the math mode punctuation symbols after this declaration as follows:

    \Umathcode"002C="6 \symPunctSymb "002C
    \Umathcode"002E="6 \symPunctSymb "002E
    \Umathcode"003A="6 \symPunctSymb "003A
    \Umathcode"003B="6 \symPunctSymb "003B
    

    The 6 index stands for math punctuation.

  3. I recommend you to remove fdsymbol package if you want or need to work with more fonts, otherwise you will likely be greeted by the error Too many fonts declared.

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.