0

In my editor I have liguatures enabled that turn || to a \/ symbol and lambda to a λ. I copy-paste a lot of code into the minted environment and its a shame that these do not carry over. Is it possible to tell minted to replace all occurances of || with the logical or symbol and all occurances of lambda with \lambda for example?

I found out that using fontspec and FiraCode translates the -> to the character arrow but this does not seem very configurable.

fakedrake
  • 123
  • 6
  • Have you seen https://tex.stackexchange.com/q/294362 ? – Thérèse Oct 19 '21 at 00:43
  • I probably shouldn't have mentioned FiraCode because that is not the direction I want to go. I don't want to replace character sequences with single unicode characters. I would prefer if I could tell latex to replace some sequences of characters (eg ->) with other sequences of characters (eg \to). – fakedrake Oct 19 '21 at 01:49
  • @fakedrake Will be tricky. Yes, an expl3 replace or regex can do a substitution, and minted when doing the verbatim environment can escape to latex code, but (manual, p24): "Note that when math is used inside escapes, any active characters beyond those that are normally active in verbatim can cause problems." and then links to: https://tex.stackexchange.com/questions/223876/fancyvrb-error-with-math-escapes-and-prime Unrelated: Interestingly, a % in a tex minted typesets the line as latex, but you have to switch to \rmfamily since monospace doesn't have ligatures. – Cicada Oct 19 '21 at 09:41

1 Answers1

1

It is a type of meta-processing.

"Telling" is where the effort is.

Example of doing expl3 replace by escaping out of minted's verbatim environment and applying a replace-command:

transliteration

Using unique identifiers, and going directly to (unicode) math glyphs, makes maintenance easier and avoids minted's math-mode glitching.

But probably easier just to type x ∈ ℜ in a unicode-math space in the first place, without needing to use a lookup command at all, and switching fonts automatically, maybe in an environment-in-an-environment (somehow). Fancyvrb's verbatim environment keeps getting in the way.

MWE

\documentclass{article}
\usepackage{xparse}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
\setmonofont{Noto Sans Mono}
\newfontface\mymfont{XITS Math}
\DeclareTextFontCommand{\textmymath}{\mymfont}
\usepackage{minted}

\ExplSyntaxOn

%===================================== \tl_new:N \l_mytrans_tl \NewDocumentCommand { \translit } { m } {% \tl_set:Nn \l_mytrans_tl { #1 } \dotranslit \tl_use:N \l_mytrans_tl }

%---- Environments \NewDocumentEnvironment{translite}{ +b } { \tl_set:Nn \l_mytrans_tl { #1 } \dotranslit \tl_use:N \l_mytrans_tl } { }

%-----
\newcommand\dotranslit{% \tl_replace_all:Nnn \l_mytrans_tl { mlambda } { $\lambda$ } \tl_replace_all:Nnn \l_mytrans_tl { xlambda } { \textmymath{} } % U+1D706 MATHEMATICAL ITALIC SMALL LAMDA \tl_replace_all:Nnn \l_mytrans_tl { xreal } {\textmymath{ℜ} } % U+211C BLACK-LETTER CAPITAL R : real part \tl_replace_all:Nnn \l_mytrans_tl { xelementof } { \textmymath{∈} } % U+2208 ELEMENT OF \tl_replace_all:Nnn \l_mytrans_tl { xmapsto } { \textmymath{↦} } % U+21A6 RIGHTWARDS ARROW FROM BAR : z notation maplet }

\ExplSyntaxOff

\begin{document}

xlambda $\mapsto$ \translit{xlambda}

\begin{minted}[linenos=true,escapeinside=||]{tex} % This is a TeX comment but is not disregarded because it's inside %| {\rmfamily ffi ffl >> -- --- } | font ligatures yes, TeX ligatures no. | {\rmfamily xlambda = \translit{xlambda} } |

| {\translit{x xmapsto y xelementof xreal}}| \documentclass{article}

\usepackage{minted}

\begin{document} Dont use $$ in \LaTeXe! % It's weird! \end{document} \end{minted}

\end{document}

Cicada
  • 10,129