# Font package changes entire appearance

My current preamble defines the following font settings

\usepackage{beton}
\usepackage[T1]{fontenc}
\usepackage[T1,euler-digits]{eulervm}
\DeclareFontSeriesDefault[rm]{bf}{sbc}


Now I'm interested in the symbols generated by the txfonts package through the command \varmathbb, however, when importing the package it also changes the default math and text font. How can I avoid this and still obtain the ability to use the \varmathbb command?

In txfonts.sty we find

\DeclareMathSymbol{\m@thbbch@rA}{\mathord}{lettersA}{129}
\DeclareMathSymbol{\m@thbbch@rB}{\mathord}{lettersA}{130}
[...other similar lines...]
\DeclareMathSymbol{\m@thbbch@rY}{\mathord}{lettersA}{153}
\DeclareMathSymbol{\m@thbbch@rZ}{\mathord}{lettersA}{154}

\DeclareMathSymbol{\varBbbk}{\mathord}{lettersA}{171}

\long\def\DoLongFutureLet #1#2#3#4{%
\def\@FutureLetDecide{#1#2\@FutureLetToken
\def\@FutureLetNext{#3}\else
\def\@FutureLetNext{#4}\fi\@FutureLetNext}
\futurelet\@FutureLetToken\@FutureLetDecide}
\def\DoFutureLet #1#2#3#4{\DoLongFutureLet{#1}{#2}{#3}{#4}}
\def\@EachCharacter{\DoFutureLet{\ifx}{\@EndEachCharacter}%
{\@EachCharacterDone}{\@PickUpTheCharacter}}
\def\m@keCharacter#1{\csname\F@ntPrefix#1\endcsname}
\def\@PickUpTheCharacter#1{\m@keCharacter{#1}\@EachCharacter}
\def\@EachCharacterDone \@EndEachCharacter{}

\DeclareRobustCommand*{\varmathbb}[1]{\gdef\F@ntPrefix{m@thbbch@r}%
\@EachCharacter #1\@EndEachCharacter}


We also find

\DeclareSymbolFont{lettersA}{U}{txmia}{m}{it}
\SetSymbolFont{lettersA}{bold}{U}{txmia}{bx}{it}
\DeclareFontSubstitution{U}{txmia}{m}{it}


What's that? The alphabet for \varmathbb is not at the standard ASCII positions (they're reserved for Fraktur letters), so the package defines a routine for transforming something like \varmathbb{ABC} to a sequence of symbols taken from the right slot.

It's possible to simplify the setting with more modern tools. The slots have an offset of 64 with respect to the ASCII code, and for each letter in the argument we need to generate the mathcode having first hexadecimal digit \symlettersA, followed by 64 plus the ASCII code of the letters (in hexadecimal as well).

\documentclass{article}

\usepackage{beton}
\usepackage[T1]{fontenc}
\usepackage[T1,euler-digits]{eulervm}
\DeclareFontSeriesDefault[rm]{bf}{sbc}

\DeclareSymbolFont{lettersA}{U}{txmia}{m}{it}
\SetSymbolFont{lettersA}{bold}{U}{txmia}{bx}{it}
\DeclareFontSubstitution{U}{txmia}{m}{it}

\DeclareMathSymbol{\varBbbk}{\mathord}{lettersA}{171}

\ExplSyntaxOn

\NewDocumentCommand{\varmathbb}{m}
{
\tl_map_function:nN { #1 } \richard_varmathbb:n
}

\cs_new_protected:Nn \richard_varmathbb:n
{
\mathchar \int_eval:n { \symlettersA * "100 + #1 + 64 } \scan_stop:
}

\ExplSyntaxOff

\begin{document}

Abc $a+b=c$

$\varmathbb{ABC}+\varmathbb{D}+\varmathbb{EFGHIJKLMNOPQRSTUVWXYZ}$

\end{document}
`

• thanks for not just providing the solution but also explaining it! Jul 11, 2022 at 9:40