Skip to content

Commit

Permalink
Reset \XeTeXlinebreaklocale when nested language is closed
Browse files Browse the repository at this point in the history
Since this is a global setting, it must be explicitly reset.
To this end, we introduce the new hook \nestedextras@<language>
which is executed after a nested language has been closed.
  • Loading branch information
jspitz committed Sep 17, 2024
1 parent f456e25 commit 7cb7508
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
11 changes: 6 additions & 5 deletions doc/polyglossia.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2330,14 +2330,15 @@ \section{Modifying or extending captions, date formats and language settings}
\meta{lang} is activated locally via \cmd\text\meta{lang} command
\item \Cmd{\noextras@\meta{lang}} stores macros that are to be executed when the language
\meta{lang} is closed
\item \Cmd{\nestedextras@\meta{lang}}\new{2.3} stores macros that are to be executed when a nested language
is closed and \meta{lang} is the active language again. This is useful
for settings that are only possible on global scale.
\end{itemize}
%
In order to redefine internal macros, we recommend to use the command \cmd\gappto.
For compatibility with \pkg{babel} the command \cmd\addto\ is also available
to the same effect. For instance, to change the \cmd\chaptername\ for language ¦lingua¦,
you can do this:
In order to redefine internal macros, we recommend to use the command \cmd\addto.
For instance, to change the \cmd\chaptername\ for language ¦lingua¦, you can do this:
\begin{verbatim}
\gappto\captionslingua{\def\chaptername{Caput}}
\addto\captionslingua{\def\chaptername{Caput}}
\end{verbatim}
%
Note that this needs to be done after the respective language has been loaded with
Expand Down
23 changes: 19 additions & 4 deletions tex/gloss-chinese.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,14 @@
\@ifundefined{xpg@orig@XeTeXlinebreakskip}{\newskip\xpg@orig@XeTeXlinebreakskip}{}
\xpg@orig@XeTeXlinebreakskip=\XeTeXlinebreakskip
\def\chinese@simplified@spacing{%
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 0.1em minus 0.01em}
\XeTeXlinebreaklocale "zh"%
\XeTeXlinebreakskip = 0pt plus 0.1em minus 0.01em%
}
\let\chinese@traditional@spacing\chinese@simplified@spacing
\def\nochinese@spacing{%
\XeTeXlinebreakskip=\xpg@orig@XeTeXlinebreakskip
\XeTeXlinebreaklocale ""}
\XeTeXlinebreakskip=\xpg@orig@XeTeXlinebreakskip%
\XeTeXlinebreaklocale ""%
}
\fi

\def\noextras@chinese{%
Expand All @@ -340,5 +342,18 @@
\chinese@simplified@spacing%
\fi%
}

\ifxetex
% \XeTeXlinebreaklocale is global,
% so we need to reset after nested language got closed
\def\nestedextras@chinese{%
\ifchinese@traditional
\chinese@traditional@spacing%
\else
\chinese@simplified@spacing%
\fi%
}
\fi

% Based on contributions of Toru Inagaki, Norio Iwase, François Charette

19 changes: 15 additions & 4 deletions tex/gloss-japanese.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,13 @@
\@ifundefined{xpg@orig@XeTeXlinebreakskip}{\newskip\xpg@orig@XeTeXlinebreakskip}{}
\xpg@orig@XeTeXlinebreakskip=\XeTeXlinebreakskip
\def\japanese@spacing{%
\XeTeXlinebreaklocale "ja"
\XeTeXlinebreakskip = 0pt plus 0.1em minus 0.01em}
\XeTeXlinebreaklocale "ja"%
\XeTeXlinebreakskip = 0pt plus 0.1em minus 0.01em%
}
\def\nojapanese@spacing{%
\XeTeXlinebreakskip=\xpg@orig@XeTeXlinebreakskip
\XeTeXlinebreaklocale ""}
\XeTeXlinebreakskip=\xpg@orig@XeTeXlinebreakskip%
\XeTeXlinebreaklocale ""%
}
\fi

\def\noextras@japanese{%
Expand All @@ -269,5 +271,14 @@
\japanese@capsformat%
\japanese@spacing%
}

\ifxetex
% \XeTeXlinebreaklocale is global,
% so we need to reset after nested language got closed
\def\nestedextras@japanese{%
\japanese@spacing%
}
\fi

% Based on contributions of Toru Inagaki, Norio Iwase, François Charette

5 changes: 5 additions & 0 deletions tex/gloss-korean.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
\XeTeXlinebreaklocale ""
\noextras@korean@common
}
% \XeTeXlinebreaklocale is global,
% so we need to reset after nested language got closed
\def\nestedextras@korean{%
\XeTeXlinebreaklocale "ko"%
}
\else % luatex
\def\inlineextras@korean{\xpg@attr@cjkspacing\xpg@korean@variant\relax}
\def\noextras@korean{%
Expand Down
3 changes: 3 additions & 0 deletions tex/polyglossia.sty
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@
\xpg_otherlanguage:nn{ \xpg_alias_add_to_option_i:nn{#2}{#1} }{ #3 }
\__xpg_lang_set_text_direction:nn{#3}{#4}
\group_end:
\cs_if_exist_use:c{ nestedextras@\languagename }
}
}
\cs_generate_variant:Nn \__xpg_foreignlanguage:nnnn {eeen}
Expand All @@ -1719,6 +1720,7 @@
\__xpg_otherlanguage:eee { #1 } { #2 } { \xpg_alias_base_lang:n { #2 } }
}{
\c_group_end_token% \group_end: does not work here!
\cs_if_exist_use:c{ nestedextras@\languagename }
}
% internal wrapper
Expand Down Expand Up @@ -1770,6 +1772,7 @@
\cs_if_exist_use:c{date@bbl@\babelname}
\__xpg_lang_set_text_direction:nn{#3}{#4}
\group_end:
\cs_if_exist_use:c{ nestedextras@\languagename }
}
}
\cs_generate_variant:Nn \__xpg_textlanguage:nnnn {nnen}
Expand Down

0 comments on commit 7cb7508

Please sign in to comment.