4

I am typesetting in Burmese language. Setting \XeTeXinterwordspaceshaping=2 gives me the desired line breaking when paragraphs are fully justified. I've tried several ways, only this option works best for me.

The problem is that I also would like to use minted package for code highlighting and the above option is interfering with minted syntax highlighting. It is mentioned that setting \XeTeXinterwordspaceshaping=2 has side-effects according to this:

https://tug.org/pipermail/xetex/2016-February/026474.html

If that's the case, I was wondering if I can confine the option to only text paragraphs and escape for minted environment. Would that be possible? Here is my MWE(I am sorry that minted requires Python and pygmentize installed):

%!TeX program = XeLaTex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article}
\XeTeXlinebreaklocale "my_MM"  %Myanmar line and character breaks
\XeTeXinterwordspaceshaping=2 %%% PLEASE EXPERIMENT  BY SETTING WITH DIFFERENT VALUES


\usepackage{fontspec}
\setmainfont{Padauk}

\usepackage{minted}
\begin{document}

သီပေါမင်း (ခရစ်နှစ် ၁၈၇၈-၁၈၈၅) သည် ကုန်းဘောင်မင်းဆက်၏ နောက်ဆုံးမင်းဖြစ်သည်။ သိရီပဝရ ဝိဇယာနန္တ ယသတိလောကာ ဓိပတိ ပဏ္ဍိတ မဟာဓမ္မရာဇာဓိရာဇာ ဖြစ်ပြီး နန်းသက် ခုနစ်နှစ်ဖြစ်သည်။
ကမ္ဘာ့ အကောင်းဆုံး

\XeTeXinterwordspaceshaping=0 %%% PLEASE EXPERIMENT  BY SETTING WITH DIFFERENT VALUES
\begin{minted}{kotlin}
fun main() {
    val name = "stranger1"        // Declare your first variable
    println("Hi, $name!")        // ...and use it!
    print("Current count:")
    for (i in 0..10) {           // Loop over a range from 0 to 10
        print(" $i")
    }
}
\end{minted}
\XeTeXinterwordspaceshaping=2 %%% PLEASE EXPERIMENT  BY SETTING WITH DIFFERENT VALUES
သီပေါမင်း (ခရစ်နှစ် ၁၈၇၈-၁၈၈၅) သည် ကုန်းဘောင်မင်းဆက်၏ နောက်ဆုံးမင်းဖြစ်သည်။ သိရီပဝရ ဝိဇယာနန္တ ယသတိလောကာ ဓိပတိ ပဏ္ဍိတ မဟာဓမ္မရာဇာဓိရာဇာ ဖြစ်ပြီး နန်းသက် ခုနစ်နှစ်ဖြစ်သည်။
ကမ္ဘာ့ အကောင်းဆုံး
\end{document}

Setting 0, I got this output (problematic rendering circled):enter image description here

Setting 2, I got this output (correct rendering in green, unintended side-effect on minted in red)enter image description here

5
  • @DavidCarlisle, I tried as suggested, but it doesn't seem to be a local setting. If the last one is set to 0, minted is okay. But once I set back to 2 for the next paragraphs, it doesn't work anymore.
    – Pyi Soe
    Commented Jul 6, 2023 at 10:37
  • 1
    Hi, as requested, I've extended the example and also hope the problem can be easier to see after adding the screenshots.
    – Pyi Soe
    Commented Jul 6, 2023 at 15:35
  • It's a bit surprising that it only affect certain parts highlighted by minted, not everything. The full test code I am trying didn't turn the bottom paragraph to red. Anyway, I hope you see the problem. Thanks!
    – Pyi Soe
    Commented Jul 6, 2023 at 15:40
  • I can confirm your output, no idea yet why the red color escapes from minted. looking.... Commented Jul 7, 2023 at 7:36
  • do you have any documentation for XeTeXinterwordspaceshaping? it's not in the xetex reference manual. there are a few comments in the xetex.web source file and xetex NEWS file, but not much :( ahh actually that email link you give explains it (a bit) Commented Jul 7, 2023 at 8:11

1 Answer 1

2

Elsewhere in the email thread that you link to, the behaviour of setting 2 is described as:

These cases are addressed with \XeTeXinterwordspaceshaping=2. With this value, not only are inter-word spaces measured in context, but also each run of text (words and intervening spaces) in a single font will be re-shaped as a unit at \shipout time. This allows full shaping (contextual swashes, ligatures, etc) to take effect across inter-word spaces.

The reference to \shipout means that it acts per-page and can not be changed for individual paragraphs.

But I think this is the output you want (I can't read the script so if this is messed up, leave a comment and I'll try again later)enter image description here

The email you link to gives a clue to use \kern0pt as a workaround to avoid bad effects, so I locally insert a kern at every \special in minted.

\documentclass[10pt]{article}
\XeTeXlinebreaklocale "my_MM"  %Myanmar line and character breaks
\XeTeXinterwordspaceshaping=2 %%% PLEASE EXPERIMENT  BY SETTING WITH DIFFERENT VALUES


\usepackage{fontspec}
\setmainfont{Padauk}
\showoutput
\usepackage{minted}
\begin{document}

သီပေါမင်း (ခရစ်နှစ် ၁၈၇၈-၁၈၈၅) သည် ကုန်းဘောင်မင်းဆက်၏ နောက်ဆုံးမင်းဖြစ်သည်။ သိရီပဝရ ဝိဇယာနန္တ ယသတိလောကာ ဓိပတိ ပဏ္ဍိတ မဟာဓမ္မရာဇာဓိရာဇာ ဖြစ်ပြီး နန်းသက် ခုနစ်နှစ်ဖြစ်သည်။
ကမ္ဘာ့ အကောင်းဆုံး

{
\let\xspecial\special
\def\special{\kern0pt\xspecial}


\begin{minted}{kotlin}
fun main() {
    val name = "stranger1"        // Declare your first variable
    println("Hi, $name!")        // ...and use it!
    print("Current count:")
    for (i in 0..10) {           // Loop over a range from 0 to 10
        print(" $i")
    }
}
\end{minted}

}% end special hack


သီပေါမင်း (ခရစ်နှစ် ၁၈၇၈-၁၈၈၅) သည် ကုန်းဘောင်မင်းဆက်၏ နောက်ဆုံးမင်းဖြစ်သည်။ သိရီပဝရ ဝိဇယာနန္တ ယသတိလောကာ ဓိပတိ ပဏ္ဍိတ မဟာဓမ္မရာဇာဓိရာဇာ ဖြစ်ပြီး နန်းသက် ခုနစ်နှစ်ဖြစ်သည်။
ကမ္ဘာ့ အကောင်းဆုံး
\end{document}
3
  • Ohh... very kind, thanks a lot. The output looks perfect, at least for this example. I believe this technique will work. I'll try a bit more and see how it goes.
    – Pyi Soe
    Commented Jul 7, 2023 at 8:56
  • 1
    You can use \AtBeginEnvironment{minted}{\let\special\mintedspecial} along with \def\mintedspecial{\kern0pt\primitive\special}, so the syntax in the document remains \begin{minted}, without extra braces.
    – egreg
    Commented Jul 7, 2023 at 9:50
  • @egreg yes although if the document has any color or tagging or hyperlinks or... you probably need that definition globally, the problem is not minted specific other than minted uses color Commented Jul 7, 2023 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .