reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
190 stars 51 forks source link

parenthesis direction in minted #536

Closed bykhov closed 2 years ago

bykhov commented 2 years ago

After the recent update, the direction of parenthesis in minted environment is wrong.

Example:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{minted,color}

\usepackage{polyglossia,bidi}
\setmainlanguage{hebrew}
\setotherlanguage{english}

\setmainfont{Times New Roman}
\setmonofont{Courier New}

\begin{document}
\begin{minted}{python}
x = [x ]
\end{minted}
\end{document}

Resulting file attached a.pdf

jspitz commented 2 years ago

Is this with XeTeX or LuaTeX?

jspitz commented 2 years ago

To answer myself: XeTeX. LuaTeX does not show the problem.

jspitz commented 2 years ago

I checked out an old polyglossia version and see the same problem. So the bug seems to be in bidi (where you also have reported the same issue without letting us know here; see https://github.com/tex-persian/bidi/issues/12)

bykhov commented 2 years ago

I checked out an old polyglossia version and see the same problem. So the bug seems to be in bidi (where you also have reported the same issue without letting us know here; see tex-persian/bidi#12)

Sorry for not informing you. Anyway, bidi maintainer convinced me that it is not bidi issue (polyglossia one?). Adding english environment solves the problem, but it previously worked fine \setLR and \setRL

bykhov commented 2 years ago

I checked out an old polyglossia version and see the same problem.

It works fine for me with polyglossia version 1.52

jspitz commented 2 years ago

It works fine for me with polyglossia version 1.52

Sorry I cannot confirm this. I checkout out older revisions of polyglossia back to v. 1.47, and all show the same output. So it must be a change in another package (such as bidi or maybe minted) that cause this. This is not to say that this isn't a problem that can/should be addressed by polyglossia, but it is certainly not a bug introduced by polyglossia.

Udi-Fogiel commented 5 months ago

@jspitz This is caused by the fact that we pass the Hebrew Script feature to the font. Maybe we should ad an option to disable this for typewriter fonts, as they are often used for listings only.

the bidi package has nothing to do with parenthesis, This is a feature of XeTeX, which applies the unicode BiDi algorithm on short chunks of text when system fonts are used, and is relying on stuff like the Script that is used to determine if parenthesis should be mirrored or not.

bykhov commented 5 months ago

I was just trying to revive some old documents last week. My workaround was \begin{english} ...\end{english} for each code block. Or, with some automation:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{minted,color}
\newminted{python}{}
\BeforeBeginEnvironment{pythoncode}{\setLR\begin{english}}
\AfterEndEnvironment{pythoncode}{\end{english}\setRL}

\usepackage{polyglossia,bidi}
\setmainlanguage{hebrew}
\setotherlanguage{english}

\setmainfont{Times New Roman}
\setmonofont{Courier New}

\begin{document}
\begin{english}
\begin{pythoncode}
x = [x ]
\end{pythoncode}
\end{english}
\end{document}
jspitz commented 5 months ago

@jspitz This is caused by the fact that we pass the Hebrew Script feature to the font. Maybe we should ad an option to disable this for typewriter fonts, as they are often used for listings only.

This strikes me like an odd solution. IMHO the language needs to be reset for the listings. Ideally minted should deal with this.

Udi-Fogiel commented 5 months ago

This strikes me like an odd solution. IMHO the language needs to be reset for the listings. Ideally minted should deal with this.

I don't think it is odd. Typewriter fonts are often treated differently. For example, fontspec does not add to them Mapping=tex-text or the +tlig features like to sans serif or serif fonts. Imagine I have only hebrew in my document, I don't really want to load the english gloss just for listings, I don't need any of its features, not even hyphenation.

jspitz commented 5 months ago

I don't think you need to load English. Setting language latex would probably do.

Udi-Fogiel commented 5 months ago

Is this documented?

jspitz commented 5 months ago

No.