4

I'm using rich unicode in LaTeX as specified here. However I also use unicode in Julia language, so when I input Julia code in XeLaTeX I get an error because √ is bound to \sqrt in LaTeX, but is a normal symbol in minted. Here's an MWE:

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}

\usepackage{newunicodechar}
\newunicodechar{√}{\sqrt}

\usepackage{minted} % uses minted 2.0+
% skip boxes on parser error:
\makeatletter
\expandafter\def\csname PYGdefault@tok@err\endcsname{\def\PYGdefault@bc##1{{\strut ##1}}}
\makeatother
% name of the code boxes:
\renewcommand\listingscaption{Код}

\usepackage{unicode-math}

\begin{document}

$√{2}$

\begin{listing}[H]
  \begin{minted}[breaklines,autogobble,linenos]{julia}
        P(a::ℝ) = k*T/A_n * (
                        (√a - 1)^(1/3) / (3 * ν^(1/3) * √a)
                      + 1 / (a - √a)
                  )
  \end{minted}
  \caption{(\ref{eq:a})\label{code:a}}
\end{listing}

$√{2}$

\end{document}

This should be compiled with xelatex -shell-escape mwe.tex. I'm looking for a way to unbind the √ inside minted environments.

3

Define the square root symbol to behave differently in minted:

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}

\usepackage{minted} % uses minted 2.0+

\usepackage{etoolbox}
\usepackage{newunicodechar}

\newtoggle{inminted}
\newunicodechar{√}{\iftoggle{inminted}{√}{\sqrt}}
\AtBeginEnvironment{minted}{\toggletrue{inminted}}

% skip boxes on parser error:
\makeatletter
\expandafter\def\csname PYGdefault@tok@err\endcsname{\def\PYGdefault@bc##1{{\strut ##1}}}
\makeatother
% name of the code boxes:
\renewcommand\listingscaption{Код}

\begin{document}

$√{2}$

\begin{listing}[H]
  \begin{minted}[breaklines,autogobble,linenos]{julia}
        P(a::ℝ) = k*T/A_n * (
                        (√a - 1)^(1/3) / (3 * ν^(1/3) * √a)
                      + 1 / (a - √a)
                  )
  \end{minted}
  \caption{(\ref{eq:a})\label{code:a}}
\end{listing}

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.