4

This question is related to this one: What are all the font styles I can use in math mode?

I would like to know if it is possible to use the command \varmathbb{}, that according to the accepted answer needs either the package txfonts or the package pxfonts (I am using the former), without extending the usage of the font to the entire document (thus leaving computer modern as the standard font).

Thanks a lot in advance for any feedback.

1
  • Indeed you are right. Terrible typo (but now corrected)!
    – Kolmin
    Commented Jan 5, 2018 at 14:22

1 Answer 1

5

Use the font defined by newtxmath, with some help (the characters are not in the standard font position).

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

% from newtxmath
\DeclareFontFamily{U}{ntxmia}{}
\DeclareFontShape{U}{ntxmia}{m}{it}{<-> ntxmia }{}
\DeclareFontShape{U}{ntxmia}{b}{it}{<-> ntxbmia }{}
\DeclareSymbolFont{lettersA}{U}{ntxmia}{m}{it}
\SetSymbolFont{lettersA}{bold}{U}{ntxmia}{b}{it}

\AtBeginDocument{\let\mathbb\varmathbb}

\ExplSyntaxOn
\NewDocumentCommand{\varmathbb}{m}
 {
  \tl_map_inline:nn { #1 }
   {
    \use:c { varbb##1 }
   }
 }
\cs_new_protected:Nn \__mathbb_define:Nn
 {
  \DeclareMathSymbol{#1}{\mathord}{lettersA}{#2}
 }
\cs_generate_variant:Nn \__mathbb_define:Nn {ce}
\tl_map_inline:nn { ABCDEFGHIJKLMNOPQRSTUVWXYZ }
 {
  \__mathbb_define:ce { varbb#1 } { \int_eval:n { `#1+67 } }
 }
\tl_map_inline:nn { abcdefghijklmnopqrstuvwxyz }
 {
  \__mathbb_define:ce { varbb#1 } { \int_eval:n { `#1+61 } }
 }
\DeclareMathSymbol{\varbbimath}{\mathord}{lettersA}{'270}
\DeclareMathSymbol{\varbbjmath}{\mathord}{lettersA}{'271}
\ExplSyntaxOff

\begin{document}

$\mathbb{A}\mathbb{B}\mathbb{C}\mathbb{R}\mathbb{Z}\mathbb{k}\mathbb{l}\mathbb{m}$

$\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZklmn}$

$\varbbimath\varbbjmath$

\end{document}

enter image description here

Old answer (kept for those who still run TeX Live 2018)

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

% from newtxmath
\DeclareFontFamily{U}{ntxmia}{}
\DeclareFontShape{U}{ntxmia}{m}{it}{<-> ntxmia }{}
\DeclareFontShape{U}{ntxmia}{b}{it}{<-> ntxbmia }{}
\DeclareSymbolFont{lettersA}{U}{ntxmia}{m}{it}
\SetSymbolFont{lettersA}{bold}{U}{ntxmia}{b}{it}

\AtBeginDocument{\let\mathbb\varmathbb}

\ExplSyntaxOn
\NewDocumentCommand{\varmathbb}{m}
 {
  \tl_map_inline:nn { #1 }
   {
    \use:c { varbb##1 }
   }
 }
\tl_map_inline:nn { ABCDEFGHIJKLMNOPQRSTUVWXYZ }
 {
  \exp_args:Nc \DeclareMathSymbol{varbb#1}{\mathord}{lettersA}{\int_eval:n { `#1+64 }}
 }
\exp_args:Nc \DeclareMathSymbol{varbbk}{\mathord}{lettersA}{169}
\ExplSyntaxOff

\begin{document}

$\mathbb{A}\mathbb{B}\mathbb{C}\mathbb{R}\mathbb{Z}\mathbb{k}$

$\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZk}$

\end{document}

enter image description here

8
  • Thanks a lot (as always). If there are no other options I will go for that, but – to me – it really looks very close to the standard \mathbb.
    – Kolmin
    Commented Jan 5, 2018 at 15:22
  • @Kolmin Sorry, I misinterpreted your requirement. Fixed.
    – egreg
    Commented Jan 5, 2018 at 15:51
  • Thanks a lot. This is (almost) what I was looking for. :-) That is, now everytime there is a \mathbbit switches automatically to that nice \varmathbb. However, can the two types of fonts coexist, with \mathbb as usual and also \varmathbb to get that nice effect?
    – Kolmin
    Commented Jan 5, 2018 at 18:07
  • 1
    @Kolmin Just remove the \AtBeginDocument{\let\mathbb\varmathbb} instruction and use \varmathbb{A} for the modified letters.
    – egreg
    Commented Jan 5, 2018 at 18:13
  • Great, thanks! (Sorry, I could open the page only now).
    – Kolmin
    Commented Jan 6, 2018 at 16:41

You must log in to answer this question.

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