jkuczm / mmacells

Mathematica cells in TeX
61 stars 18 forks source link

Polyglossia monofont error #30

Closed Anton-Sakovich closed 8 years ago

Anton-Sakovich commented 8 years ago

Greetings again, jkuczm.

The issue is the following. Let us consider Xe(La)TeX + polyglossia bundle for non-english (russian in my case) document preparation.

There is a well-known issue with polyglossia package that an error

! Package polyglossia Error: The current roman font does not contain the Cyrill
ic script!
(polyglossia)                Please define \cyrillicfont with \newfontfamily.

See the polyglossia package documentation for explanation.

arises while using some verbatim environments like Verbatim one provided by fancyvrb package, which is used by mmacells. One can find a solution (see e.g. http://tex.stackexchange.com/questions/91507/liberation-mono-the-current-roman-font-does-not-contain-the-cyrillic-script on tex.stackexchange.com) for this problem to add a string \newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf} in a document.

The point is that, while this string helps in case of Verbatim environment and, furthermore, there is no any problem with lstlisting environment, even without this "help-string", mmaCell environment still leads to above mentioned error. I.e. this "help-string" doesn't help in the case of mmaCell environment.

For clarity:

\documentclass[a4paper,10pt]{article}

\usepackage[quiet]{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{mmacells}

\setmainfont[Ligatures=NoCommon]{Times New Roman}
\setmathfont{xits-math.otf}
\setmainlanguage{russian}
\setotherlanguage{english}
%\newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf}

\begin{document}

Русский текст.

\begin{Verbatim}
  f[x]
\end{Verbatim}

\end{document}

leads to error, while

\documentclass[a4paper,10pt]{article}

\usepackage[quiet]{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{mmacells}

\setmainfont[Ligatures=NoCommon]{Times New Roman}
\setmathfont{xits-math.otf}
\setmainlanguage{russian}
\setotherlanguage{english}
\newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf}

\begin{document}

Русский текст.

\begin{Verbatim}
  f[x]
\end{Verbatim}

\end{document}

does not. I don't even need to declare english environment explicitly.

And this one

\documentclass[a4paper,10pt]{article}

\usepackage[quiet]{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{mmacells}

\setmainfont[Ligatures=NoCommon]{Times New Roman}
\setmathfont{xits-math.otf}
\setmainlanguage{russian}
\setotherlanguage{english}
\newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf}

\begin{document}

Русский текст.

\begin{mmaCell}{Input}
  f[x]
\end{mmaCell}

\end{document} 

leads to the error anyway.

So, maybe something in mmacells package just doesn't let this trick to work?

P.S. LaTeX + fontenc + inputenc + babel bundle seems to work fine, i.e.

\documentclass[a4paper,10pt]{article}

\usepackage{mmacells}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}

\begin{document}

Русский текст.

\begin{mmaCell}{Input}
  f[x]
\end{mmaCell}

\end{document}

works fine. But sometimes it's necessary to use XeTeX...

P.P.S. Oh, by the way, I omitted \begin{english} and \end{english} because it does not help without help-string present anyway (this is the bug of polyglossia) and after explicit redefining there is no need of them. But

\documentclass[a4paper,10pt]{article}

\usepackage[quiet]{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{mmacells}

\setmainfont[Ligatures=NoCommon]{Times New Roman}
\setmathfont{xits-math.otf}
\setmainlanguage{russian}
\setotherlanguage{english}
\newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf}

\begin{document}

Русский текст.

\begin{english}
\begin{mmaCell}{Input}
  f[x]
\end{mmaCell}
\end{english}

\end{document}

still doesn't work, while

\documentclass[a4paper,10pt]{article}

\usepackage[quiet]{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{mmacells}

\setmainfont[Ligatures=NoCommon]{Times New Roman}
\setmathfont{xits-math.otf}
\setmainlanguage{russian}
\setotherlanguage{english}
\newfontfamily\cyrillicfonttt{lmmonolt10-bold.otf}

\begin{document}

Русский текст.

\begin{english}
\begin{Verbatim}
  f[x]
\end{Verbatim}
\end{english}

\end{document}

does.

Anton-Sakovich commented 8 years ago

Uph, after a day of fighting against the system, I have understood that I was digging in the wrong way.

The reason was not in the mmaCells-fancyvrb interaction, but just in the fact that not only mono type fonts are used but sans serif ones are used too. So,

\newfontfamily\cyrillicfonttt{lmmonolt10-regular.otf}
\newfontfamily\cyrillicfontsf{lmsans10-regular.otf}

fooled polyglossia and allowed my document to be compiled. So, the problem is not the problem of mmaCells (actually, it is the problem of fancyvrb-polyglossia interaction).

The only task left is to find appropriate fonts, but it is another story... I am sorry for the mess I created here.

jkuczm commented 8 years ago

This is a problem of interaction between polyglossia and specific font you use. It's not related to mmacells nor to fancyvrb. You don't need Verbatim nor mmaCell environment to reproduce it, all you need is \ttfamily or \sffamily somewhere in your document. Verbatim (and mmaCell) uses the former for code and mmaCell, by default, uses the latter for labels.

From mmacells side, label formatting can be changed by using labelstyle key, either for specific cell: \begin{mmaCell}[labelstyle=...]{Input}..., or globally: \mmaSet{labelstyle=...}.