Problem loading different fonts in standalone
05:27 28 Apr 2026

I'm trying to use two different fonts to build standalone figures, that I then use in presentations, videos, etc. So far I was having success, with a code like the following:

\documentclass[border=10,multi={general,answer,question}]{standalone}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{endiagram, plimsoll}

\usepackage{chemfig, chemmacros, chemformula, modiagram}
\chemsetup{formula={chemformula}}
\chemsetup[chemformula]{arrow-style={{line width=2}}}
\chemsetup[redox]{roman=false, pos=top, explicit-sign=true}

\usepackage{xcolor}
\definecolor{green}{HTML}{039855}
\definecolor{red}{HTML}{B52209}
\definecolor{yellow}{HTML}{D19F24}
\definecolor{purple}{HTML}{8C6188}
\definecolor{ansblue}{HTML}{0061A0}
\definecolor{ansred}{HTML}{FF0000}
\definecolor{ansyellow}{HTML}{FFFF00}
\definecolor{questionblue}{HTML}{032254}
\definecolor{black}{RGB}{0,0,0}

\usepackage[most]{tcolorbox}
\tcbset{on line, 
        boxsep=4pt, left=0pt,right=0pt,top=0pt,bottom=0pt,
        colframe=ansred,colback=ansyellow,  
        highlight math style={enhanced}
        }

% 1. FUENTES DE TEXTO
\setmainfont[Path=../../]{Kalam-Regular.ttf}
\setsansfont[Path=../../]{NotoSans.ttf}

% 2. FUENTE BASE (Solo para símbolos que no están en el range)
\setmathfont{Latin Modern Math}

% 3. ENTORNOS CON CARGA DINÁMICA
\newenvironment{general}{%
    \rmfamily
    \color{green}
    \setmathfont[Path=../../, range={up/{latin,Latin,num}, it/{latin,Latin}, "002B, "003D, "2212, "002D, "00AD, "0028, "0029}]{Kalam-Regular.ttf}
    \setcharge{.style={fill=green}}
    \setchemfig{
        chemfig style={line width=2pt, color=green},
        compound style={color=green},
        double bond sep={4pt},
        arrow double sep=6pt,
        arrow style={thick, line width=2, color=green}
        }
}{%
}

\newenvironment{answer}{%
    \rmfamily
    \color{ansblue}
    \setmathfont[Path=../../, range={up/{latin,Latin,num}, it/{latin,Latin}, "002B, "003D, "2212, "002D, "00AD, "0028, "0029}]{Kalam-Regular.ttf}
    \setcharge{.style={fill=ansblue}}
    \setchemfig{
        chemfig style={line width=2pt, color=ansblue},
        compound style={color=ansblue},
        double bond sep={4pt},
        arrow double sep=6pt,
        arrow style={thick, line width=2, color=ansblue}
        }
}{%
}

\newenvironment{question}{%
    \sffamily
    \color{questionblue}
    \setmathfont[Path=../../, range={up/{latin,Latin,num}, it/{latin,Latin}, "002B, "003D, "002D, "2212, "00AD, "0028, "0029}]{NotoSans.ttf}
    \setcharge{.style={fill=questionblue}}
    \setchemfig{
        chemfig style={line width=2pt, color=questionblue},
        compound style={color=questionblue},
        double bond sep={4pt},
        arrow double sep=6pt,
        arrow style={thick, line width=2, color=questionblue}
        }
    \renewcommand*\printatom[1]{\ensuremath{\mathsf{##1}}}
}{%
}

\begin{document}
\Huge

\begin{question}
\ch{2 CO\gas{} + 2 NO\gas{} -> 2 CO2\gas{} + N2\gas}
\end{question}

\begin{answer}
$\begin{aligned}
\sum_{broken} BE &= 2\times BE(\chemfig{C~[,.5]O}) + 2\times BE(\chemfig{N=[,.5]O}) = 3328\ kJ \\
\sum_{formed} BE &= 4\times BE(\chemfig{C=[,.5]O}) + BE(\chemfig{N~[,.5]N}) = 4161\ kJ \\
\Delta H &= 3328 \minus 4161 = \fcolorbox{ansred}{ansyellow}{$\minus 833\ kJ$}
\end{aligned}$
\end{answer}

\begin{general}
\chemfig{\charge{[circle]180=\:}{C}~\charge{[circle]0=\:}{O}}
\end{general}

\begin{general}
\chemfig{\charge{[circle]-120=\:, 120=\.}{N}=\charge{[circle]60=\:, -60=\:}{O}}
\end{general}

\begin{general}
\chemfig{\charge{[circle]-120=\:, 120=\:}{O}=C=\charge{[circle]60=\:, -60=\:}{O}}
\end{general}

\begin{general}
$\begin{aligned}
\Delta H &= \sum_{broken} BE \minus \sum_{formed} BE \\
\Delta H &= 3328 \minus 4161 = \minus 833\ kJ
\end{aligned}$
\end{general}

\begin{general}
$\begin{aligned}
\sum_{broken} BE &= 2\times BE(\chemfig{C~[,.5]O}) + 2\times BE(\chemfig{N=[,.5]O}) \\
\sum_{broken} BE &= (2)(1077) + (2)(587) = 3328\ kJ \\
\sum_{formed} BE &= 4\times BE(\chemfig{C=[,.5]O}) + BE(\chemfig{N~[,.5]N}) \\
\sum_{formed} BE &= (4)(804) + 945 = 4161\ kJ
\end{aligned}$
\end{general}

\end{document}

The problem is that I have a limit (I don't know if it's memory or something, I'm not that of an expert). If I add just one more environment, it crashes with the following:

[{
    "resource": "/C:/Users/Tomas/Documents/Revision Village/CH2456a/CH2456a tex/CH2456a.tex",
    "owner": "LaTeX",
    "severity": 8,
    "message": "Too many symbol fonts declared.",
    "source": "LaTeX",
    "startLineNumber": 123,
    "startColumn": 1,
    "endLineNumber": 123,
    "endColumn": 65536,
    "modelVersionId": 682,
    "origin": "extHost1"
},{
    "resource": "/C:/Users/Tomas/Documents/Revision Village/CH2456a/CH2456a tex/CH2456a.tex",
    "owner": "LaTeX",
    "severity": 8,
    "message": "Symbol font `__um_fam8' not defined.",
    "source": "LaTeX",
    "startLineNumber": 123,
    "startColumn": 1,
    "endLineNumber": 123,
    "endColumn": 65536,
    "modelVersionId": 682,
    "origin": "extHost1"
},{
    "resource": "/C:/Users/Tomas/Documents/Revision Village/CH2456a/CH2456a tex/CH2456a.tex",
    "owner": "LaTeX",
    "severity": 8,
    "message": "Missing number, treated as zero.\n",
    "source": "LaTeX",
    "startLineNumber": 123,
    "startColumn": 1,
    "endLineNumber": 123,
    "endColumn": 65536,
    "modelVersionId": 682,
    "origin": "extHost1"
}]

How can I solve this?
I'm working with TexLive + VS Code on Windows11.

xetex fontspec