reutenauer / polyglossia

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

Caption and pseudo code in algorithm2e appears as boxes (not rendered) using polyglossia #134

Closed sereysethy closed 5 years ago

sereysethy commented 8 years ago

I want to create a multi-language document using polyglossia in which Khmer is set to be a main language and English as another language. I also have khmer-gloss.ldf available so that Khmer font is a default font. I used to algorithm2e to typeset pseudo code, but strangely all pseudo codes appears as boxes as in picture below and even caption does not display either. I know it is the problem of font but I am pretty new to polyglossia package. Anybody knows how to solve this problem? The below pseudo code is just an example.

\documentclass{article}
\usepackage{polyglossia}
\usepackage{amsthm}
\usepackage{amssymb,amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}

\newfontfamily{\khmerfont}[Script=Khmer,BoldFont={Khmer OS Content},ItalicFont={Khmer OS Content},Scale=0.9]{Khmer OS Content}
\usepackage{fontspec}
\newfontfamily{\K}[Scale=0.90]{Khmer OS Content}
\newfontfamily{\T}[Scale=0.90]{Khmer OS Moul}

\setmainlanguage{khmer}
\setsansfont[Script=Khmer,Scale=0.95]{Khmer OS Content}
\setmonofont[Script=Khmer,Scale=0.95]{Khmer OS Content}
\setotherlanguage{english}

\begin{document}
អាល់កូរីតដើម្បីរកតួចែករួមធំបំផុត (\textenglish{PGCD})។
\begin{algorithm}
\begin{english}
    \SetKwInOut{Input}{\textenglish{Input}}
    \SetKwInOut{Output}{\textenglish{Output}}

    \underline{function Euclid} $(a,b)$\;
    \Input{Two non negative integers $a$ and $b$}
    \Output{$\gcd(a,b)$}
    \eIf{$b=0$}
      {
        return $a$\;
      }
      {
        return Euclid$(b, a \mod b)$\;
      }
    \caption{\textenglish{Euclid's algorithm for finding the greatest common divisor of two non negative integers}}
\end{english}
\end{algorithm}

\end{document}
waclc

Just for reference, the package algorithm is working fine with polyglossia I just need to typeset the following:

\begin{algorithm}
\begin{english}
   \caption{Merge Sort}
   \begin{algorithmic}[1]
    ...
    ...
   \end{algorithmic}
\end{english}
\end{algorithm}
sayol commented 8 years ago

I ran your code and it produced an error. I changed Moul to Muol and it worked pretty fine.

\documentclass{article}
\usepackage{polyglossia}
\usepackage{amsthm}
\usepackage{amssymb,amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}

\newfontfamily{\khmerfont}[Script=Khmer,BoldFont={Khmer OS Content},ItalicFont={Khmer OS Content},Scale=0.9]{Khmer OS Content}
\usepackage{fontspec}
\newfontfamily{\K}[Scale=0.90]{Khmer OS Content}
\newfontfamily{\T}[Scale=0.90]{Khmer OS Muol}

\setmainlanguage{khmer}
\setsansfont[Script=Khmer,Scale=0.95]{Khmer OS Content}
\setmonofont[Script=Khmer,Scale=0.95]{Khmer OS Content}
\setotherlanguage{english}

\begin{document}
អាល់កូរីតដើម្បីរកតួចែករួមធំបំផុត (\textenglish{PGCD})។
\begin{algorithm}
\begin{english}
    \SetKwInOut{Input}{\textenglish{Input}}
    \SetKwInOut{Output}{\textenglish{Output}}

    \underline{function Euclid} $(a,b)$\;
    \Input{Two non negative integers $a$ and $b$}
    \Output{$\gcd(a,b)$}
    \eIf{$b=0$}
      {
        return $a$\;
      }
      {
        return Euclid$(b, a \mod b)$\;
      }
    \caption{\textenglish{Euclid's algorithm for finding the greatest common divisor of two non negative integers}}
\end{english}
\end{algorithm}

\end{document}

algorithm

sereysethy commented 8 years ago

The only difference between your code and mine is this line \newfontfamily{\T}[Scale=0.90]{Khmer OS Muol} and \newfontfamily{\T}[Scale=0.90]{Khmer OS Moul}. And the rest is the same.

Somehow my pseudo codes are displayed as boxes. What environment do you have on your computer?

sereysethy commented 8 years ago

Actually if you have file gloss-khmer.ldf present in your folder, english font will be displayed as boxes. If you run it without gloss-khmer.ldf, everything is ok.

sayol commented 8 years ago

What did you mean by environment? I am using TeXLive 2015 on window 7. I am afraid that your TeX distribution is not up to date, or you do not have Khmer OS installed on your system.

sereysethy commented 8 years ago

I also use TeX Live 2015 but on Mac. I have Khmer OS installed otherwise there would be no Khmer font displayed.

sayol commented 8 years ago

Make sure that Khmer OS was installed correctly on your system! Try other Khmer font families available on your system other than Khmer OS. Otherwise, test it with this version of gloss-khmer.ldf

\ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
\PolyglossiaSetup{khmer}{
    script=Khmer,%
    scripttag=khmr,%
    langtag=KHM,%
    hyphennames={nohyphenation},%
    fontsetup=true%
}
\newif\if@khmer@numerals
\def\tmp@khmer{khmer}
\define@key{khmer}{numerals}[khmer]{%
    \def\@tmpa{#1}%
    \ifx\@tmpa\tmp@khmer\@khmer@numeralstrue%
    \else\@khmer@numeralsfalse\fi%
}
\setkeys{khmer}{numerals}
\def\captionskhmer{%
    \def\prefacename{អារម្ភកថា}%
    \def\refname{ឯកសារយោង}%
    \def\abstractname{សង្ខេប}%
    \def\bibname{គន្ថនិទ្ទេស}%
    \def\chaptername{ជំពូក}%
    \def\appendixname{សេចក្ដីបន្ថែម}%
    \def\contentsname{មាតិកា}%
    \def\listfigurename{បញ្ជីរូបភាព}%
    \def\listtablename{បញ្ជីតារាង}%
    \def\indexname{សន្ទស្សន៍}%
    \def\figurename{រូប}%
    \def\tablename{តារាង}%
    \def\partname{ផ្នែក}%
    \def\pagename{ទំព័រ}%
    \def\seename{មើល}%
    \def\alsoname{មើលបន្ថែម}%
    \def\enclname{ឯកសារភ្ជាប់}%
    \def\ccname{ចម្លងជួន}%
    \def\headtoname{ផ្ញើរទៅ}%
    \def\proofname{សម្រាយ}%
    \def\answername{ចម្លើយ}%
    \def\glossaryname{សទានុក្រម}%
}
\def\datekhmer{%
    \def\khmer@month{%
        \ifcase\month\or%
        មករា\or%
        កុម្ភៈ\or%
        មិនា\or%
        មេសា\or%
        ឧសភា\or%
        មិថុនា\or%
        កក្កដា\or%
        សីហា\or%
        កញ្ញា\or%
        តុលា\or%
        វិច្ឆិកា\or%
        ធ្នូ\fi}%
    \def\today{\khmernumber\day\space\khmer@month\space\khmernumber\year}%
}
\def\khmerdigits#1{\expandafter\@khmer@digits #1@}
\def\@khmer@digits#1{%
    \ifx @#1% then terminate
    \else\ifx0#1០%
    \else\ifx1#1១%
    \else\ifx2#1២%
    \else\ifx3#1៣%
    \else\ifx4#1៤%
    \else\ifx5#1៥%
    \else\ifx6#1៦%
    \else\ifx7#1៧%
    \else\ifx8#1៨%
    \else\ifx9#1៩%
    \else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@khmer@digits%
    \fi
}
\def\khmernumber#1{%
    \if@khmer@numerals%
        \khmerdigits{\number#1}%
    \else%
        \number#1%
    \fi}
\def\khmer@globalnumbers{%
    \let\orig@arabic\@arabic%
    \let\@arabic\khmernumber%
    \renewcommand{\thefootnote}{\protect\khmernumber{\c@footnote}}%
}
\def\nokhmer@globalnumbers{%
    \let\@arabic\orig@arabic%
    \renewcommand\thefootnote{\protect\number{\c@footnote}}%
}
\def\thepart{\arabic{part}}
\def\@khmeralph#1{%
\ifcase#1%
\or ក\or ខ\or គ\or ឃ\or ង%
\or ច\or ឆ\or ជ\or ឈ\or ញ%
\or ដ\or ឋ\or ឌ\or ឍ\or ណ%
\or ត\or ថ\or ទ\or ធ\or ន%
\or ប\or ផ\or ព\or ភ\or ម%
\or យ\or រ\or ល\or វ\or ស\or ហ\or ឡ\or អ%
\else\xpg@ill@value{#1}{@khmeralph}\fi}
\def\khmerAlph#1{\expandafter\@khmerAlph\csname c@#1\endcsname}
\def\@khmerAlph#1{%
\ifcase#1%
\or ក\or ខ\or គ\or ឃ\or ង%
\or ច\or ឆ\or ជ\or ឈ\or ញ%
\or ដ\or ឋ\or ឌ\or ឍ\or ណ%
\or ត\or ថ\or ទ\or ធ\or ន%
\or ប\or ផ\or ព\or ភ\or ម%
\or យ\or រ\or ល\or វ\or ស\or ហ\or ឡ\or អ%
\else\xpg@ill@value{#1}{@khmeralph}\fi}
\def\khmer@numbers{%
    \let\@latinalph\@alph%
    \let\@latinAlph\@Alph%
    \if@khmer@numerals
        \let\@alph\@khmeralph%
        \let\@Alph\@khmerAlph%
    \fi%
}
\def\nokhmer@numbers{%
    \let\@alph\@latinalph%
    \let\@Alph\@latinAlph%
}
\def\blockextras@khmer{%
    \XeTeXlinebreaklocale "kh"% 
    \XeTeXlinebreakskip = 0pt plus1pt minus1pt%
}
\def\noblockextras@khmer{% 
    \XeTeXlinebreaklocale "en"%
}
\@ifclassloaded{beamer}{%
\mode<presentation>{
    \usefonttheme{professionalfonts}%
    \def\factname{ស្វ័យសត្យ}%
    \def\lemmaname{បទគន្លិះ}%
    \def\theoremname{ទ្រឹស្ដីបទ}%
    \def\corollaryname{អនុសាធ្យ}%
    \def\problemname{ចំណោទ}%
    \def\solutionname{ដំណោះស្រាយ}%
    \def\definitionname{និយមន័យ}%
    \def\examplename{ឧទាហរណ៏}%
    \uselanguage{khmer}%
    \languagepath{khmer}%
    \deftranslation[to=khmer]{Fact}{\factname}%
    \deftranslation[to=khmer]{Lemma}{\lemmaname}%
    \deftranslation[to=khmer]{Theorem}{\theoremname}%
    \deftranslation[to=khmer]{Corollary}{\corollaryname}%
    \deftranslation[to=khmer]{Problem}{\problemname}%
    \deftranslation[to=khmer]{Solution}{\solutionname}%
    \deftranslation[to=khmer]{Definition}{\definitionname}%
    \deftranslation[to=khmer]{Definitions}{\definitionname}%
    \deftranslation[to=khmer]{Example}{\examplename}%
    \deftranslation[to=khmer]{Examples}{\examplename}%
    \AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\def\noexpand%
        \inserttotalframenumber{\noexpand\khmernumber{\the\c@framenumber}}}}}}%
    }%
}{}
\endinput
sereysethy commented 8 years ago

Yes I tried with your file gloss-khmer.ldf but no luck. I think there is something wrong with my environment, because I can see khmer text is rendered just fine អាល់កូរីតដើម្បីរកតួចែករួមធំបំផុត.

sayol commented 8 years ago

Test this following minimal working example!

\documentclass{article}
\usepackage{polyglossia}
\newfontfamily{\khmerfont}{Khmer OS}
\setmonofont{Khmer OS}
\setmainlanguage{khmer}
\setotherlanguage{english}
\begin{document}
    សាកល្បង try this one \textenglish{English text} តើអត្ថបទជាភាសាអង់គ្លេសនៅក្រៅបរិស្ថានភាសាអង់គ្លេសចេញជ្រុងៗឬទេ?
\end{document}

error1

sereysethy commented 8 years ago

Well when I changed the BoldFont to a default font in Mac Khmer Sangam MN or any other fonts except Khmer OS in \newfontfamily{\khmerfont}[Script=Khmer,BoldFont={Khmer OS Content},ItalicFont={Khmer OS Content},Scale=0.9]{Khmer OS Content}, everything works fine.

I think the problem is the attribute BoldFont.

sayol commented 8 years ago

@sereysethy Pretty great! You solved it!

sereysethy commented 8 years ago

By the way your file gloss-khmer.ldf looks great except it translates all numbers to khmer numbers which to me is not something that I want. I prefer normal numbers.

Thank you.

sereysethy commented 8 years ago

Thank you.

Sethy

On Mon, Feb 22, 2016 at 3:32 PM, Say OL notifications@github.com wrote:

@sereysethy https://github.com/sereysethy Pretty great! You solved it!

— Reply to this email directly or view it on GitHub https://github.com/reutenauer/polyglossia/issues/134#issuecomment-187069477 .

sayol commented 8 years ago

Just use \setmainlanguage[numerals=arabic]{khmer} if you prefer Arabic numerals!

sereysethy commented 8 years ago

Cool. I stop using LaTeX for so long... I almost forget some commands and I am pretty new to polyglossia. Again thank you.

jspitz commented 5 years ago

This ticket can be closed. No polyglossia bug.