我尝试使用\newenvironment
XeLaTeX 下的命令fontspec
和polyglossia
包,但新环境的关闭命令似乎无法识别。我该如何让它工作?
这是一个最简单的代码:
\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}
“Times 3 中的文本”无法正确显示,因为它仍保留在 Nirmala 中。我得到:
! 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
我正在使用 Windows 10、Miktex 和 Texmaker。
答案1
当你这样做时\newenvironment{Tam}{...x...}{...y...}
,你应该使用
\begin{Tam}
<text>
\end{Tam}
不是\Tam{<text>}
。
也不要使用\begin{texttamil}
。
\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}