1

I'm trying to make an environment that uses sans-serif math by default inside the environment, but not outside of it. To do this I'm using the sansmath package.

The problem is that, when used with \usepackage[libertine]{newtxmath}

Here's an example:

\documentclass[10pt]{article}

\usepackage[tt=false, type1=true]{libertine}
\usepackage[libertine]{newtxmath} %works if I remove this
\usepackage{sansmath}


\begin{document}
$(0 + 1) + 2$

\begin{sansmath}
$(3 + 4) + 5$
\end{sansmath}
\end{document}

The non-sans part displays fine, but the brackets in the sans section don't show up at all. They do if I remove the newtxmath package.

Is there something I can do to get sansmath and libertine working together?

2
  • 1
    This sems to be related to the combination of nextxmath and sansmath but not to libertine itself. (And loading sansmath before newtxmath, while restoring the missing parentheses and plus signs, of course fails to use sans serif fonts inside the sansmath environment.
    – murray
    Jan 7 at 21:40
  • 1
    It looks like the sansmath package is not compatible with the libertine font when used with the newtxmath package. You could use the sansmathaccent package, which provides a way to use the libertine math font with the sansmath package:
    – John Smith
    Jan 8 at 1:42

1 Answer 1

1

In Unicode Engines

In unicode-math, you can load Libertinus Math as your main math font, and another with version=sans. This cuts the Gordian knot of legacy 8-bit font encodings.

\documentclass[10pt]{article}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }

\setmainfont{Libertinus Serif}[Scale=1.0]
\setsansfont{Libertinus Sans}
\setmathfont{Libertinus Math}
\setmathfont{kpmath-sans}[version=sans]

\newenvironment{sansmath}{\mathversion{sans}}

\begin{document}
$(0 + 1) + 2$

\begin{sansmath}
$(3 + 4) + 5$
\end{sansmath}
\end{document}

Libertinus Math + KP Sans sample

In PDFTeX

You can try patching in the math alphabet from the newtxsf package.

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{libertinus}

\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{\encodingdefault}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathit}{sans}{\encodingdefault}{\sfdefault}{m}{it}
\SetMathAlphabet{\mathsf}{sans}{\encodingdefault}{\sfdefault}{m}{n}
\SetMathAlphabet{\mathbf}{sans}{\encodingdefault}{\sfdefault}{b}{n}
\SetSymbolFont{letters}{sans}{OML}{ntxsfmi}{m}{it}
% \SetSymbolFont{lettersA}{sans}{U}{ntxsfmia}{m}{it}

\newenvironment{sansmath}{\mathversion{sans}}


\begin{document}
$(0 + 1) + 2$

\begin{sansmath}
$(3 + 4) + 5$
\end{sansmath}
\end{document}

Newtx + Libertinus + Newtxsf sample

You must log in to answer this question.

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