Custom math mode font

fontsfontspecmath-fontsmath-mode

I created a custom font Computer Modern Roman Blackboard Bold, similar to the Computer Modern Roman - italic as the following image:

enter image description here

As you can imagine, I want to implement this font in math-mode such as \cmrbb{hello} or maybe substitute \mathsf alphabet for mine, then rename a new command \cmrbb.

Specifications

  • I'm using fontspec
  • I'm using LuaLaTeX
  • I have some packages like amsmath, amssymb, mathtools (I don't know if it can cause trouble)
  • I want to use the new font as a simple command like \cmrbb{text} inside math-mode
  • I'm working currently on Overleaf and have loaded cmrbb.ttf

I have no idea how I can do it, I tried using mathspec but the document doesn't even compile (I think it only works in XeLaTeX).

And just in case there is no incompatibility, I don't use any command for font encoding, and I have already loaded some fonts. I don't know much about fontspec, any additional information to make it easier to implement the solution would be really helpful.

Best Answer

It's not clear if your font is OT1 encoded like the original cmr or TU Unicode encoded, but basically

\DeclareMathAlphabet      {\cmrbb}{OT1}{cmrbb}{m}{n}

or

\DeclareMathAlphabet      {\cmrbb}{TU}{cmrbb}{m}{n}

together with a suitable fd file if using OT1 and declare the font using \newfontfamily\cmrbbfam[NFSSFamily=cmrbb] if using TU encoded fonts.

An example (produced with xelatex) using some opentype font found on this system, the declarations would be the same for any font.

enter image description here

\documentclass{article}
\usepackage{fontspec}

\newfontfamily\cmrbbfam{Goudy Stout}[NFSSFamily=cmrbb]
\DeclareMathAlphabet      {\cmrbb}{TU}{cmrbb}{m}{n}

\begin{document}


\[
  a=\cmrbb{N}+\cmrbb{xyz} + y
  \]
\end{document}