jkuczm / mmacells

Mathematica cells in TeX
61 stars 18 forks source link

Has conflict with the package unicode-math. #18

Closed szsdk closed 8 years ago

szsdk commented 8 years ago

This is the minimal tex file.

\documentclass{article}
\usepackage{unicode-math}
\usepackage{mmacells}

\begin{document}
\begin{mmaCell}{Input}
  \mmaSub{x}{1}==\mmaFrac{-b\(\pm\)\mmaSqrt{\mmaSup{b}{2}-4 a c}}{2 a}
\end{mmaCell}
\end{document}

I get the error "Improper alphabetic constant". And I am using texlive 2015.

jkuczm commented 8 years ago

Thanks for reporting it.

This seems to be an issue of listings interface with fancyvrb, since following gives the same error:

\documentclass{article}
\usepackage{unicode-math}
\usepackage{listings}
\usepackage{fancyvrb}

\begin{document}
\lstset{fancyvrb}
\begin{Verbatim}[commandchars=\\\{\}]
\pm
\end{Verbatim}
\end{document}

So I'm not sure if it can be easily fixed in mmacells package.


A workaround for such cases is to use relevant Unicode character (in this case ±), instead of TeX commands (\(\pm\) in this case):

\documentclass{article}
\usepackage{mmacells}
\usepackage{unicode-math}

\begin{document}

\mmaSet{moreliterate={±}{{±}}1}

\begin{mmaCell}{Input}
  \mmaSub{x}{1}==\mmaFrac{-b±\mmaSqrt{\mmaSup{b}{2}-4 a c}}{2 a}
\end{mmaCell}

\end{document}
szsdk commented 8 years ago

I've asked this question in tex.se. Conflict with unicode-math and listings

\pm is internally defined as "the character ±". In the listings code \pm is used in an \lccode assigment but its value is much too large. You can avoid the problem by converting \pm to a macro. This is handled differently by listings.

And this is the solution given.

\documentclass{article}
\usepackage{unicode-math}
\usepackage{listings}
\usepackage{fancyvrb}

\AtBeginDocument{%
 \let\ORIpm\pm
 \renewcommand\pm{\ORIpm}}

\begin{document}

\lstset{fancyvrb}
\begin{Verbatim}[commandchars=\\\{\}]
\pm
\end{Verbatim}

\end{document}
jkuczm commented 8 years ago

Since version 0.3.0 of mmacells package, one can completely switch off listings, which is source of all Unicode-related problems.

This will also switch off automatic highlighting of identifiers, so all of them need to annotated, but code with all annotations can be automatically generated by CellsToTeX package (since version 0.2.0).

With listings switched off one can simply, directly use Unicode characters inside mmaCell:

\documentclass{article}
\usepackage{mmacells}
\usepackage{unicode-math}
\begin{document}

\mmaSet{uselistings=false}

\begin{mmaCell}{Input}
\mmaSub{\mmaUnd{x}}{1}==\mmaFrac{-\mmaUnd{b}±\mmaSqrt{\mmaSup{\mmaUnd{b}}{2}-4 \mmaUnd{a} \mmaUnd{c}}}{2 \mmaUnd{a}}
\end{mmaCell}

\end{document}

result