[Tex/LaTex] “Argument of \reserved@a has an extra }” error when using non-English language in \title

memoirxetex

(Other answers (A, B) with similar error message do not actually take care of the situation.)

I have memoir document which should contain title both in Bangla and English. But when compiled (using xelatex), I get an error message,

! Argument of \reserved@a has an
extra }.

Here is the MWE which causes the error.

\documentclass{memoir}

\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage[numerals=Devanagari]{bengali}

\title{\begin{bengali} বইয়ের টাইটেল\end{bengali}
  Book Title}

\begin{document}

\maketitle

\end{document}

If the part \begin{bengali} বইয়ের টাইটেল\end{bengali} is taken out of the file,
the error disappears. So, that line must the culprit here.

As is advised in the questions (or answers) mentioned at the top, I need to protect something. However, I am a little confused what to protect here. I even tried putting \protect around \begin{bengali} বইয়ের টাইটেল\end{bengali}, without any avail. (Just a hunch, not an educated one.)

Best Answer

The \begin macro which starts an environment is "fragile", which means it cannot be used inside a moving argument. The \title command expands its argument, and therefore fragile commands can't be used inside it.

See the following question for an explanation of this.

So the solution is to not use the {bengali} environment inside the title.

(You could actually "protect" the environment by using \protect\begin{bengali} .... \protect\end{bengali}) but there is a simpler solution:

Just use \textbengali{}:

\documentclass{memoir}

\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage[numerals=Devanagari]{bengali}
\newfontfamily\bengalifont[]{Bangla MN}
\title{\textbengali{বইয়ের টাইটেল}
  Book Title}

\begin{document}

\maketitle
\end{document}

output of code