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.

Kolmin
  • 559

1 Answers1

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

egreg
  • 1,121,712
  • 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 Jan 05 '18 at 15:22
  • @Kolmin Sorry, I misinterpreted your requirement. Fixed. – egreg Jan 05 '18 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 Jan 05 '18 at 18:07
  • 1
    @Kolmin Just remove the \AtBeginDocument{\let\mathbb\varmathbb} instruction and use \varmathbb{A} for the modified letters. – egreg Jan 05 '18 at 18:13
  • Great, thanks! (Sorry, I could open the page only now). – Kolmin Jan 06 '18 at 16:41
  • The solution works great (+1), except (for some reasons beyond my understanding) I had to change \int_eval:n { \#1+64 }into\int_eval:n { `#1+67 }to make it work in my document. Otherwise,\varmathbb{R}` would print letter "O" and similarly all other letters be shifted back by 3. – AndreasT Dec 20 '21 at 04:39
  • @egreg (I don't know if I should open a new question for this) Related to my previous comment, your code on exactly the same document gives different results if compiled on two different laptops (in mine I need the +67 fix, whereas in another one the original +64 works). Any reason why this is the case? – AndreasT Dec 21 '21 at 01:13
  • @AndreasT The fonts changed and moved the letters three positions forward. – egreg Dec 21 '21 at 09:09