2

I'm trying to use the \newenvironment command under XeLaTeX with the fontspec and polyglossia packages, and it seems that the closing commands of the new environment is not recognized. How can I make it work?

Here's a minimal code:

\documentclass[a4paper,12pt]{report}
\usepackage{fontspec}
\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage{tamil}

\setmainfont{Times New Roman}
\newfontfamily{\texttamil}{Nirmala UI}
\newenvironment{Tam}{\begin{texttamil}}{\end{texttamil}}

\begin{document}
text in Times 1
\begin{texttamil}
உடல் text in Nirmala 1
\end{texttamil}
text in Times 2
\Tam{உடல் text in Nirmala 2}
text in Times 3
\end{document}

"text in Times 3" is not correctly displayed since it remains in Nirmala. I get:

! LaTeX Error: \begin{texttamil} on input line 18 ended by \end{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.20 \end{document}

?
[1] (Default.aux) )
(\end occurred inside a group at level 1)

### semi simple group (level 1) entered at line 18 (\begingroup)
### bottom levelstdin -> Default.pdf
[1]
27625 bytes written

I'm using Windows 10, Miktex and Texmaker.

  • You define Tam as an environment, but then use it as a macro: why? – egreg Sep 13 '16 at 10:26
3

When you do \newenvironment{Tam}{...x...}{...y...}, you should use

\begin{Tam}
<text>
\end{Tam}

not \Tam{<text>}.

Don't use \begin{texttamil} either.

\documentclass[a4paper,12pt]{report}
\usepackage{fontspec}
\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage{tamil}

\setmainfont{Times New Roman}
\newfontfamily{\texttamil}{Tamil Sangam MN} % the one I have
\newenvironment{Tam}
  {\texttamil\ignorespaces}
  {\ignorespacesafterend}

\begin{document}

text in Times 1
{\texttamil உடல் text in Nirmala 1}
text in Times 2
\begin{Tam}
உடல் text in Nirmala 2
\end{Tam}
text in Times 3

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.