1

First of all a code that compiles well

% !TEX TS-program = xelatex
\documentclass[11pt,a4paper]{article}
\usepackage{xgreek}
\usepackage{unicode-math}
\setmainfont{Linux Libertine O}
\begin{document}

\newcounter{n}%
\setcounter{n}{0}%

\makeatletter
 \@for\liste:={{a=1},{b=2},{c=-2}}\do{%
 \stepcounter{n}%
 \begingroup
 \nogreekalph
 \global\expandafter\let\csname arg\alph{n}\endcsname\liste
 \endgroup
 }%
 \makeatother

$\arga $ ; $\argb$ ; $\argc$

Αυτό είναι μια υπο-επικεφαλίδα
\end{document}

Now I want to use polyglossia. With the code below, several errors occur

% !TEX TS-program = xelatex
\documentclass[11pt,a4paper]{article}
\usepackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage[variant=polytonic]{greek}
\usepackage{xgreek}
\usepackage{unicode-math}
\setmainfont{Linux Libertine O}

\begin{document}

\newcounter{n}%
\setcounter{n}{0}%

\makeatletter
 \@for\liste:={{a=1},{b=2},{c=-2}}\do{%
 \stepcounter{n}%
 \begingroup
 \nogreekalph
 \global\expandafter\let\csname arg\alph{n}\endcsname\liste
 \endgroup
 }%
 \makeatother

$\arga $ ; $\argb$ ; $\argc$

Αυτό είναι μια υπο-επικεφαλίδα
\end{document}

How to change the following code to avoid these errors

 \nogreekalph
 \global\expandafter\let\csname arg\alph{n}\endcsname\liste

The problem is the same with babel

2
  • Using a representation like \alph{n} in a \csname is normally not a good idea, you can't be sure that it expands. I would use expl3 and \int_to_alph:n. Feb 14, 2020 at 18:35
  • @UlrikeFischer Currently I don't know enough about expl3 to find a solution. Feb 14, 2020 at 20:15

1 Answer 1

2

An expl3 version of such a loop could look like this. It assumes that you defining a new command. If you want to redefine existing ones you will have to adjust the code.

\documentclass[11pt,a4paper]{article}
\usepackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage[variant=polytonic]{greek}
\usepackage{xgreek}
\usepackage{unicode-math}
\setmainfont{Linux Libertine O}

\begin{document}

\ExplSyntaxOn
\clist_set:Nn \l_tmpa_clist { {a=1},{b=2},{c=-2} }
\int_zero:N\l_tmpa_int
\clist_map_inline:Nn \l_tmpa_clist
 {
  \int_incr:N \l_tmpa_int
  \cs_new:cpn { arg \int_to_alph:n { \l_tmpa_int } } { #1 }
 }
\ExplSyntaxOff

$\arga $ ; $\argb$ ; $\argc$

Αυτό είναι μια υπο-επικεφαλίδα
\end{document}

enter image description here

2
  • Thanks Ulrike !! expl3 impresses me more and more; At the moment I don't understand the code but I'm going to work on it. The problem in my code comes from \nogreekalph. How do I turn \nogreekalph on and off ? only on when the language chosen is Greek. Feb 14, 2020 at 22:15
  • as I already said: it is a bad idea to use a command like \alph in a \csname. As you just learned you can't never be sure that is expands, as a number of packages redefines it. Whatever code you use at the end, it shouldn't use \alph in this place. Feb 14, 2020 at 22:23

You must log in to answer this question.

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