Lualatex 与 polyglossia 的 \setotherlanguages 和 ntheorem 错误

Lualatex 与 polyglossia 的 \setotherlanguages 和 ntheorem 错误

考虑一下这个MWE:

\documentclass[10pt,twoside,openright]{book}

% http://tex.stackexchange.com/a/44701/2595
\usepackage{iftex}
\ifPDFTeX
  \usepackage[greek,danish,english]{babel}
  \usepackage[utf8]{inputenc}
  \usepackage[T1]{fontenc}
  \usepackage{lmodern}
\else
  \usepackage{polyglossia}
  \setdefaultlanguage{english}
  \setotherlanguages{greek,danish} %% (A): causes "Command \proofname already defined."; do it after ntheorem?
  \ifXeTeX
    \usepackage{xltxtra}
  \else
    \usepackage{luatextra}
  \fi
  \defaultfontfeatures{Ligatures=TeX}
\fi

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[framed,amsmath,amsthm,thmmarks]{ntheorem}
% \ifPDFTeX \else %% (B):
%   \setotherlanguages{greek,swedish} % polyglossia leftover; causes "Command \greek already defined."
% \fi

\usepackage{lipsum}

\begin{document}
\lipsum[1]
\end{document}

用 编译它lualatex --file-line-error test.tex,我得到:

...
(/media/texlive/2014/texmf-dist/tex/latex/ntheorem/ntheorem.sty
Style `ntheorem', Version 1.33 <2011/08/15>
(/media/texlive/2014/texmf-dist/tex/latex/base/ifthen.sty)

/media/texlive/2014/texmf-dist/tex/latex/ntheorem/ntheorem.sty:1175: 
LaTeX Error: Command \proofname already defined.
               Or name \end... illegal, see p.192 of the manual.

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

l.1175 \ProcessOptions\relax

? 

在看到“命令 \proofname 已经定义”后,我尝试查看一下polyglossia.dtx

$ awk 'BEGIN{tdo=0;} 
  /captions(danish|swedish|.*greek)/ {print $0; tdo=1;}     
  /proofname/{if(tdo==1){print $0; tdo=0;}}
' `kpsewhich polyglossia.dtx` 

\def\captionsdanish{%
  \def\proofname{Bevis}%
\def\captionsgreek{\monogreekcaptions}%
    \def\captionsgreek{\polygreekcaptions}%
      \def\captionsgreek{\ancientgreekcaptions}%
      \def\captionsgreek{\monogreekcaptions}%
   \def\proofname{Απόδειξη}%
\def\captionsswedish{%
  \def\proofname{Bevis}%

...事实上,所有语言都会重新定义\proofname;所以我的第一个想法是在 MWE 中用 (B) 替换 (A) - 但结果是“命令 \greek 已定义。”。

现在有趣的是:这个错误发生在(A)仅有的{greek,danish}用于\setotherlanguages- 它确实不是发生在,比如说,{greek,swedish}或者只是{greek}!(请注意,(B)中的错误也发生在瑞典语中

我能做的最好的事情就是比较丹麦语和瑞典语的多语文件,看看是否存在差异——我试过了

meld `kpsewhich gloss-swedish.ldf` `kpsewhich gloss-danish.ldf`

... 我看不出有什么显著的区别?!

所以我的问题是 - 如何使用polyglossia而不\setotherlanguages{greek,danish}崩溃?

答案1

如果你确实想使用polyglossia则重置\proofname为未定义:

[...]
\usepackage{amsmath}
\usepackage{amssymb}
\let\proofname\relax
\usepackage[framed,amsmath,amsthm,thmmarks]{ntheorem}
[...]

答案2

好的,我想我已经接近知道为什么会发生这种情况了;我尝试过追踪:

...
\usepackage{trace}
...
  \traceon
  \setotherlanguages{greek,danish} %% (A): causes "Command \proofname already defined."; do it after ntheorem?
  \traceoff
...

{greek,danish}.. 并比较和的输出{greek,swedish}。对于瑞典语,相关跟踪是:

{blank space  }
{\par}
{\def}
{changing \captionsswedish=undefined}
{into \captionsswedish=macro:->\def \refname {Referenser}\def \abstractname \ETC
.}
{blank space  }
{\par}
{\def}
{changing \dateswedish=undefined}
{into \dateswedish=macro:->\def \today {\number \day ~\ifcase \ETC.}
{blank space  }
{\par}
{\endinput}
)
{\catcode}

... 对于丹麦语来说,它是:

{blank space  }
{\par}
{\def}
{changing \captionsdanish=undefined}
{into \captionsdanish=macro:->\def \prefacename {Forord}\def \refname \ETC.}
{\def}
{changing \proofname=undefined}
{into \proofname=macro:->Bevis}
{\def}
{changing \glossaryname=undefined}
{into \glossaryname=macro:->Gloseliste}
{\def}
{changing \today=macro:->\ifcase \month \or January\or Fe\ETC.}
{into \today=macro:->\number \day .~\ifcase \month \or \ETC.}
{blank space  }
{\par}
{\endinput}
)
{\catcode}

不知何故,除了 之外\captionsdanish,此代码路径还设法 def和\proofname。为什么?让我们比较一下 .ldf 文件;有:\glossaryname\todaygloss-swedish.ldf

\def\captionsswedish{%
...
  \def\proofname{Bevis}%
  \def\glossaryname{Ordlista}%
  }

\def\dateswedish{%   
  \def\today{%
... }%
    }

... 同时gloss-danish.ldf具有:

\def\captionsdanish{%
...
  \def\alsoname{Se også}}% <--- !!
  \def\proofname{Bevis}%
  \def\glossaryname{Gloseliste}%
  \def\today{\number\day.~\ifcase\month\or
...}

如果你仔细观察,你\def\alsoname会发现关闭括号}},因此第二个括号关闭\captionsdanish,并将\defs 留给\proofname\glossaryname并且\today“裸露”在“根级别”上;因此当此文件执行时,它们就会执行!

据我所知,在gloss-english.ldf\captionsenglish- 它的设置方式与 相同\captionsswedish;所以我猜这是 中的语法错误\captionsdanish。所以,我猜,要真正修复此处的错误,必须干预gloss-danish.ldf。就版本而言,为了将来参考,我有这些显示此问题的版本:

$ grep '\ProvidesPackage' $(kpsewhich polyglossia.sty)
\ProvidesPackage{polyglossia}[2014/05/21 v1.33.5

$ lualatex
This is LuaTeX, Version beta-0.79.1 (TeX Live 2014) (rev 4971) 

相关内容