0

I'm writting a simple math book but I have a problem with the pi sign. I'm using a font which doesn't have the sign so it appears like this:

Pi problem

This is how I wrote it:

\textbf{Perímetro:} $2\pi r$\\
\textbf{Área:} $r\pi^2$\\+

And this is how I applied the font:

\newfontfamily{\miletra}{MILETRA}[
  NFSSFamily=MiLetra,
  Path=./,
  Extension=.ttf,
  UprightFont=*,
  BoldFont=*,
  BoldFeatures={FakeBold=3},
]

\renewcommand{\familydefault}{MiLetra}

\DeclareSymbolFont{numbers}{TU}{MiLetra}{m}{n}
\SetSymbolFont{numbers}{bold}{TU}{MiLetra}{bx}{n}
\DeclareMathSymbol{0}\mathalpha{numbers}{"30}
\DeclareMathSymbol{1}\mathalpha{numbers}{"31}
\DeclareMathSymbol{2}\mathalpha{numbers}{"32}
\DeclareMathSymbol{3}\mathalpha{numbers}{"33}
\DeclareMathSymbol{4}\mathalpha{numbers}{"34}
\DeclareMathSymbol{5}\mathalpha{numbers}{"35}
\DeclareMathSymbol{6}\mathalpha{numbers}{"36}
\DeclareMathSymbol{7}\mathalpha{numbers}{"37}
\DeclareMathSymbol{8}\mathalpha{numbers}{"38}
\DeclareMathSymbol{9}\mathalpha{numbers}{"39}

\DeclareSymbolFont{operators}{TU}{MiLetra}{m}{n}
\DeclareSymbolFontAlphabet{\mathsf}{operators}

\DeclareSymbolFont{letters}{TU}{MiLetra}{m}{n}
\DeclareSymbolFontAlphabet{\mathsf}{letters}

How can I make LaTeX use the pi sign from its math font without changing my font?

Thanks in advance.

10
  • 1
    I just noticed the ^2 should be on r, I will fix that too haha
    – ian
    Jan 15 at 17:45
  • 3
    obviously \pi normally works so the problem is with code you have not shown,. Please fix your question to have an example that produces the output shown. Jan 15 at 17:46
  • 1
    Welcome. // @ian, your >pruned< code should start with \documentclass, and at \end{document} and contain your code posted so far AND anything else which we need for a copy & compile run. The way you have simply doesn't. Thanks. (See David's last comment, and you know why ...)
    – MS-SPO
    Jan 15 at 17:52
  • 1
    You still have not shown any code that would produce the output shown. The declaration you added just defines a text font and would not affect math mode Jan 15 at 17:52
  • 1
    @ian, just prepare a document with the two lines that fails, adding the preamble needed to show the error. You can also read what a minimal working example (MWE) is.
    – Rmano
    Jan 15 at 18:05

2 Answers 2

7

A more reasonable example would be

\documentclass{article}

\usepackage{fontspec}
\newfontfamily{\miletra}{Comic Sans MS}[
  NFSSFamily=MiLetra,
  UprightFont=*,
  BoldFont=*,
  BoldFeatures={FakeBold=3},
]

\DeclareSymbolFont{letters}{TU}{MiLetra}{m}{n}
\begin{document}

\textbf{Perímetro:} $2\pi r$

\textbf{Área:} $\pi r^2$
\end{document}

(I picked a well known font without Greek)

You can define a symbol font using classic tex math encoding and redefine \pi to use that (copied from fontmath.ltx just changing letters to grletters

enter image description here

\documentclass{article}

\usepackage{fontspec}
\newfontfamily{\miletra}{Comic Sans MS}[
  NFSSFamily=MiLetra,
  UprightFont=*,
  BoldFont=*,
  BoldFeatures={FakeBold=3},
]

\DeclareSymbolFont{letters}{TU}{MiLetra}{m}{n}
\DeclareSymbolFont{grletters}{OML}{cmm} {m}{it}

\DeclareMathSymbol{\pi}{\mathord}{grletters}{"19}

\begin{document}

\textbf{Perímetro:} $2\pi r$

\textbf{Área:} $\pi r^2$
\end{document}
6

If you can use \newfontfamily, you can use unicode-math, with something like:

\usepackage[math-style=upright]{unicode-math}

\defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX}
\setmainfont{Miletra}[Scale=1.0]
\setmathfont{Fira Math} % Or your math font of choice
\setmathfont{Miletra}[range=up/{Latin,latin,digits}]

While I don’t have your font to test, this will fall back to the Fira Math font for all symbols other than Latin letters and digits.

2
  • yes, I wondered if I should have suggested a unicode math answer.+1 here OP has a choice of fonts now:-) Jan 15 at 19:29
  • @DavidCarlisle Your answer was very good! As is often the case, there was more than one way to do it, so I thought I’d post an alternative.
    – Davislor
    Jan 16 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .