0

I am using ucharclasses to use multiple languages. I am using Noto Serif font for English. But ucharclasses is also changing minted codes into Noto Serif which should be Source Code Pro instead. How do I make ucharclasses escape minted?

Update after egreg's comment:

\usepackage{fontspec}
\usepackage{minted}
\usepackage[Latin, Bengali, Devanagari]{ucharclasses}

\newfontfamily\englishfont{Noto Serif}[BoldFont=Noto Serif Bold, ItalicFont=Noto Serif Italic]
\newfontfamily\bengalifont{SolaimanLipi}[BoldFont=SolaimanLipi Bold, Scale=1.2]
\newfontfamily\monof{Source Code Pro}[NFSSFamily=SCP]


\setTransitionsForLatin{\englishfont}{\bengalifont}

\setminted[C++]{fontfamily=SCP, frame=single, fontsize=\footnotesize}


\begin{minted}{C++}
#include<iostream>
\end{minted}

The last code block should load with Source Code pro. But it is loading with Noto Serif.

4
  • 1
    Can you please add a minimal example?
    – egreg
    Jan 11, 2022 at 18:30
  • @egreg Updated my question Jan 11, 2022 at 18:44
  • 1
    You can set \XeTeXinterchartokenstate=0 locally to disable the mechanism Jan 11, 2022 at 19:20
  • your example can not be run as is, it is much better to provide it as a complete document a form that people can run to see the issue. Jan 11, 2022 at 19:21

2 Answers 2

1

You can add

\AtBeginEnvironment{minted}{\disableTransitionRules}

to locally disable the transition mechanism.

Alternatively, if you don't plan to use the formatcom option, you can do

\setminted{formatcom=\disableTransitionRules}

Full example

\documentclass{article}

\usepackage{fontspec}
\usepackage{minted}
\usepackage[Latin, Bengali, Devanagari]{ucharclasses}

\newfontfamily\englishfont{Noto Serif}[BoldFont=Noto Serif Bold, ItalicFont=Noto Serif Italic]
\newfontfamily\bengalifont{fontkalpurush.ttf}
\newfontfamily\monof{Source Code Pro}[NFSSFamily=SCP]

\setTransitionsForLatin{\englishfont}{\bengalifont}

\AtBeginEnvironment{minted}{\disableTransitionRules}
%\setminted{formatcom=\disableTransitionRules}
\setminted[C++]{fontfamily=SCP, frame=single, fontsize=\footnotesize}


\begin{document}

\begin{minted}{C++}
#include<iostream>
\end{minted}

\end{document}

enter image description here

I've no preference about the methods. If your LaTeX is old, the \setminted strategy will work with no additional package. For the \AtBeginEnvironment you'd need etoolbox.

0

You can locally disable the xetex charclass mechanism:

enter image description here

\documentclass{article}



\usepackage{fontspec}
\usepackage{minted}
\usepackage[Latin, Bengali, Devanagari]{ucharclasses}

\newfontfamily\englishfont{Noto Serif}[BoldFont=Noto Serif Bold, ItalicFont=Noto Serif Italic]
\newfontfamily\bengalifont{Kalpurush}
\newfontfamily\monof{Source Code Pro}[NFSSFamily=SCP]


\setTransitionsForLatin{\englishfont}{\bengalifont}

\setminted[C++]{fontfamily=SCP, frame=single, fontsize=\footnotesize}

\begin{document}

\showoutput

{\XeTeXinterchartokenstate=0
\begin{minted}{C++}
#include<iostream>
\end{minted}
}

\begin{minted}{C++}
#include<iostream>
\end{minted}

\end{document}

(I changed the fonts as I did not have all the ones you used)

You must log in to answer this question.

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