Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

带cn参数后出现`\lvert' already defined等错误 #59

Closed
registor opened this issue Oct 10, 2019 · 11 comments
Closed

带cn参数后出现`\lvert' already defined等错误 #59

registor opened this issue Oct 10, 2019 · 11 comments

Comments

@registor
Copy link

编译环境Ubuntu19.04+TeXLive2019,2019年10月10日,使用sudo tlmgr update --all进行了更新。

无论是使用TXLive2019发行版中的“elegantbook.cls”还是使用Github中的“elegantbook.cls”当使用\documentclass[cn, 11pt]{elegantbook}引入宏包,编译无法通过,出现Command `\lvert' already defined等错误(应该是newtxmath与其它宏包冲突引起的)。

测试代码:

\documentclass[cn, 11pt]{elegantbook}
\begin{document}
  欢迎来到\LaTeX 世界!
\end{document}

但不使用cn参数时,工作正常,如:

\documentclass[11pt]{elegantbook}
\usepackage{ctex}%为了使用中文,若纯英文,也正常
\begin{document}
  欢迎来到\LaTeX 世界!
\end{document}

附件是出错后的log文件。
test.log

@EthanDeng
Copy link
Member

EthanDeng commented Oct 10, 2019

参考 tlmgr update newtx 冲突

@registor
Copy link
Author

谢谢楼上EthanDeng的回复!

同时,发现elegantpaper.cls这个文档类不存在这个问题,经仔细阅读其源代码,发现二者之间有一个区别是:\RequirePackage{amsmath,amssymb}这两个宏包的引入在ctex宏包之前。调整后,不再发生冲突,调整后的代码为:

\PassOptionsToPackage{no-math}{fontspec}

\RequirePackage{amsmath,amssymb}

\ifdefstring{\ELEGANT@lang}{cn}{
\RequirePackage[UTF8, scheme=plain]{ctex}
}

但,在后续使用中又发现另一个问题:当有\footnote时,会出现:

xdvipdfmx:fatal: Could not find encoding file "ntxsups_T1.enc".

No output PDF file written.
(see the transcript file for additional information)
Error 256 (driver return code) generating output;
file test.pdf may not be valid.
Transcript written on test.log.

这样的错误,打开生成的PDF时,会出现错误:

无法打开文档“/.../test-ElegantBook/test.pdf”。
PDF document is damaged

目前查到,这是由于newtx升级时没有正确处理文件名大小写的问题引起的。一个解决方案是:https://tex.stackexchange.com/questions/511573/latest-newtx-package-update-v1-601-oct-2-2019-breaks-the-footnote-command-up/511608#511608

我没有采用这个方案,而将elegantbook.cls中的% \RequirePackage{newtxtext}宏包引用暂时注释,等待newtx处理后再使用这一宏包。

@registor
Copy link
Author

今天执行sudo tlmgr update --all后,发现newtx更新到52340(1.603)版本,经测试,footnote问题已得到解决。

@xyh-cosmo
Copy link

我在“elegantbook.cls”中调整了“常用宏包”的加载位置(挪到cls的前部),这样就可以解决问题了。

@sierxue
Copy link

sierxue commented Nov 4, 2019

我在“elegantbook.cls”中调整了“常用宏包”的加载位置(挪到cls的前部),这样就可以解决问题了。

我挪到cls的前部(试了最前部,以及 \ProvidesClass{elegantbook} 之后),还是不能正确编译。

@xyh-cosmo
Copy link

xyh-cosmo commented Nov 4, 2019

我在“elegantbook.cls”中调整了“常用宏包”的加载位置(挪到cls的前部),这样就可以解决问题了。

我挪到cls的前部(试了最前部,以及 \ProvidesClass{elegantbook} 之后),还是不能正确编译。

你对比一下我的修改试试

Click to expand!
%%%%%%%%%%%%%%%%%%%%%%
%% start of file `elegantbook.cls'.
%% Copyright 2013-2019 ElegantLaTeX (elegantlatex2e@gmail.com)
%%
%% This work may be distributed and/or modified freely
%% available at https://github.com/ElegantLaTeX/ElegantBook
% 
%%%%%%%%%%%%%%%%%%%%%
% % !Mode:: "TeX:UTF-8"
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{elegantbook}[2019/08/18 v3.09 ElegantBook document class]

%% 常用宏包
\linespread{1.3}

\RequirePackage{graphicx}
%\RequirePackage{enumerate}
\RequirePackage{amsmath,mathrsfs,amsfonts,amssymb}
\RequirePackage{booktabs}
\RequirePackage{multicol,multirow}
\RequirePackage{xcolor}
\RequirePackage{fancyvrb}
\RequirePackage{makecell,lipsum,hologo,setspace}

\RequirePackage{kvoptions}
\RequirePackage{etoolbox}
\SetupKeyvalOptions{family=ELEGANT, prefix=ELEGANT@, setkeys=\kvsetkeys}
\newcommand{\ekv}[1]{\kvsetkeys{ELEGANT}{#1}}

% ----- Colors -----
\DeclareStringOption[blue]{color}
\DeclareStringOption[en]{lang}
\DeclareStringOption[answer]{result}
\DeclareStringOption[fancy]{mode}
\DeclareStringOption[show]{base}
\DeclareStringOption[normal]{device}
\DeclareStringOption[numbers]{cite}
\DeclareStringOption[newtxmath]{math}
\DeclareStringOption[marginfalse]{marginpar}
\DeclareStringOption[onecol]{toc}
% ----- backward compatibility
\DeclareVoidOption{green}{\ekv{color=green}}
\DeclareVoidOption{cyan}{\ekv{color=cyan}}
\DeclareVoidOption{blue}{\ekv{color=blue}}
\DeclareVoidOption{gray}{\ekv{color=gray}}
\DeclareVoidOption{black}{\ekv{color=black}}
\DeclareVoidOption{nocolor}{\ekv{color=none}}

\DeclareVoidOption{en}{\ekv{lang=en}}
\DeclareVoidOption{cn}{\ekv{lang=cn}}

\DeclareVoidOption{fancy}{\ekv{mode=fancy}}
\DeclareVoidOption{simple}{\ekv{mode=simple}}

\DeclareVoidOption{answer}{\ekv{result=answer}}
\DeclareVoidOption{noanswer}{\ekv{result=noanswer}}

\DeclareVoidOption{hide}{\ekv{base=hide}}
\DeclareVoidOption{show}{\ekv{base=show}}

\DeclareVoidOption{normal}{\ekv{device=normal}}
\DeclareVoidOption{pad}{\ekv{device=pad}}

\DeclareVoidOption{numbers}{\ekv{cite=numbers}}
\DeclareVoidOption{authoryear}{\ekv{cite=authoryear}}

\DeclareVoidOption{newtxmath}{\ekv{math=newtx}}
\DeclareVoidOption{mtpro2}{\ekv{math=mtpro2}}

\DeclareVoidOption{margintrue}{\ekv{marginpar=margintrue}}
\DeclareVoidOption{marginfalse}{\ekv{marginpar=marginfalse}}

\DeclareVoidOption{onecol}{\ekv{toc=onecol}}
\DeclareVoidOption{twocol}{\ekv{toc=twocol}}

% ----- Math option -----
\newcommand\mailto[1]{\href{mailto:#1}{\nolinkurl{#1}}}

% ----- Title Style -----
\DeclareStringOption[hang]{titlestyle}[hang]
% ----- backward compatibility
\DeclareVoidOption{hang}{\ekv{titlestyle=hang}}
\DeclareVoidOption{display}{\ekv{titlestyle=display}}
% ----- Default Options -----
\DeclareDefaultOption{\PassOptionsToClass{\CurrentOption}{book}}

\ProcessKeyvalOptions*\relax
% \ProcessOptions*\relax
\LoadClass[a4paper,oneside,openany]{book}

\RequirePackage{indentfirst,comment}
\setlength\parindent{2em}

% fontsetting
\ifdefstring{\ELEGANT@math}{mtpro2}{
\let\Bbbk\relax
\RequirePackage[lite]{mtpro2}
}{\relax}


\PassOptionsToPackage{no-math}{fontspec}
\ifdefstring{\ELEGANT@lang}{cn}{
\RequirePackage[UTF8, scheme=plain]{ctex}
}

\RequirePackage{ifxetex}



\RequirePackage{newtxtext}
\RequirePackage{anyfontsize}
\ifdefstring{\ELEGANT@math}{newtxmath}{
\RequirePackage{newtxmath}
\RequirePackage{esint}
%%% use yhmath pkg, uncomment following code
% \let\oldwidering\widering
% \let\widering\undefined
% \RequirePackage{yhmath}
% \let\widering\oldwidering

%%% use esvect pkg, uncomment following code
% \RequirePackage{esvect}
\DeclareSymbolFont{CMlargesymbols}{OMX}{cmex}{m}{n}
\let\sumop\relax\let\prodop\relax
\DeclareMathSymbol{\sumop}{\mathop}{CMlargesymbols}{"50}
\DeclareMathSymbol{\prodop}{\mathop}{CMlargesymbols}{"51}
}{\relax}

% ----- Handle Colors -----
%% 章节以及页脚图形

\RequirePackage{xcolor}
\ifdefstring{\ELEGANT@color}{green}{
  \definecolor{structurecolor}{RGB}{0,120,2}%
  \definecolor{main}{RGB}{0,120,2}%
  \definecolor{second}{RGB}{230,90,7}%
  \definecolor{third}{RGB}{0,160,152}%
}{\relax}
\ifdefstring{\ELEGANT@color}{cyan}{
  \definecolor{structurecolor}{RGB}{31,186,190}%
  \definecolor{main}{RGB}{59,180,5}%
  \definecolor{second}{RGB}{175,153,8}%
  \definecolor{third}{RGB}{244,105,102}%
}{\relax}
\ifdefstring{\ELEGANT@color}{blue}{
  \definecolor{structurecolor}{RGB}{60,113,183}
  \definecolor{main}{RGB}{0,166,82}%
  \definecolor{second}{RGB}{255,134,24}%
  \definecolor{third}{RGB}{0,174,247}%
}{\relax}
\ifdefstring{\ELEGANT@color}{gray}{
  \definecolor{structurecolor}{RGB}{150,150,150}
  \definecolor{main}{RGB}{150,150,150}%
  \definecolor{second}{RGB}{150,150,150}%
  \definecolor{third}{RGB}{150,150,150}%
}{\relax}
\ifdefstring{\ELEGANT@color}{black}{
  \definecolor{structurecolor}{RGB}{0,0,0}
  \definecolor{main}{RGB}{0,0,0}%
  \definecolor{second}{RGB}{0,0,0}%
  \definecolor{third}{RGB}{0,0,0}%
}{\relax}

%green color
  \definecolor{structure1}{RGB}{0,120,2}%
  \definecolor{main1}{RGB}{0,120,2}%
  \definecolor{second1}{RGB}{230,90,7}%
  \definecolor{third1}{RGB}{0,160,152}%
%cyan color
  \definecolor{structure2}{RGB}{31,186,190}%
  \definecolor{main2}{RGB}{59,180,5}%
  \definecolor{second2}{RGB}{175,153,8}%
  \definecolor{third2}{RGB}{244,105,102}%
%blue color
  \definecolor{structure3}{RGB}{60,113,183}
  \definecolor{main3}{RGB}{0,166,82}%
  \definecolor{second3}{RGB}{255,134,24}%
  \definecolor{third3}{RGB}{0,174,247}%
% gray color
  \definecolor{structure4}{RGB}{150,150,150}
  \definecolor{main4}{RGB}{150,150,150}%
  \definecolor{second4}{RGB}{150,150,150}%
  \definecolor{third4}{RGB}{150,150,150}%
% black color
  \definecolor{structure5}{RGB}{0,0,0}
  \definecolor{main5}{RGB}{0,0,0}%
  \definecolor{second5}{RGB}{0,0,0}%
  \definecolor{third5}{RGB}{0,0,0}%

% corlor definition
\definecolor{winered}{rgb}{0.5,0,0}
\definecolor{bule}{RGB}{18,29,57}


\newcommand{\base}[2]{%
  \nointerlineskip \vspace{0.1\baselineskip}\hspace{\fill}
  {\color{#1}
  	\resizebox{0.3\linewidth}{1.5ex}
  	{{%
  			{\begin{tikzpicture}
  				\node  (C) at (0,0) {};
  				\node (D) at (4,0) {};
  				\path (C) to [ornament=#2] (D);
  				\end{tikzpicture}}}}}%
  \hspace{\fill}
  \par\nointerlineskip \vspace{0.1\baselineskip}
}

% ----- Title Style -----
\ifdefstring{\ELEGANT@titlestyle}{hang}{\def\style{hang}}{\relax}
\ifdefstring{\ELEGANT@titlestyle}{display}{\def\style{display}}{\relax}


\newtoks\email
\newtoks\version
\newtoks\institute
\newtoks\subtitle

\RequirePackage[sort&compress]{natbib}
\setlength{\bibsep}{0.0pt}
\def\bibfont{\footnotesize}



\RequirePackage{enumerate}
% list/itemize/enumerate setting
\RequirePackage[shortlabels,inline]{enumitem}
\setlist{nolistsep}

% caption settings 
\RequirePackage[font=small,labelfont={bf,color=structurecolor}]{caption} 
\captionsetup[table]{skip=3pt}
\captionsetup[figure]{skip=3pt}

\AtBeginDocument{
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
\setcounter{tocdepth}{1}
\RequirePackage[flushmargin]{footmisc}
\setlength{\footnotesep}{12pt}
}

\ifdefstring{\ELEGANT@toc}{twocol}{
\renewcommand{\tableofcontents}{%
\setlength{\columnsep}{2em}
%\setlength{\columnseprule}{.8pt}
\begin{multicols}{2}[\chapter*{\contentsname}]%
\@starttoc{toc}%
\end{multicols}}
}{\relax}


%%% 常用宏包
%\linespread{1.3}

%\RequirePackage{graphicx}
%%\RequirePackage{enumerate}
%\RequirePackage{amsmath,mathrsfs,amsfonts,amssymb}
%\RequirePackage{booktabs}
%\RequirePackage{multicol,multirow}
%\RequirePackage{xcolor}
%\RequirePackage{fancyvrb}
%\RequirePackage{makecell,lipsum,hologo,setspace}

@EthanDeng
Copy link
Member

EthanDeng commented Nov 4, 2019

根据群里的反馈,将 ams 系列的宏包挪到 ctex 宏包之前就没事了,已经将此修改应用到模板中。

@stone-zeng
Copy link

根据群里的反馈,将 ams 系列的宏包挪到 ctex 宏包之前就没事了,已经将此修改应用到模板中。

这样会使英文字体变为 Latin Modern,见 https://github.com/xueruini/thuthesis/pull/434#issuecomment-539444722

ctex 下一个版本准备不再自动载入 (xe)CJKfntef 包,可以掩盖住问题。现在可以临时 hack 一下:

% 加在 \documentclass 之前
\RequirePackage{expl3}
\makeatletter
\@namedef{ver@xeCJKfntef.sty}{9999/99/99}
\makeatother
\ExplSyntaxOn
\keys_define:nn { xeCJK / options }
  {
    underdot     / format .tl_set:N = \l_tmpa_tl,
    underline    / format .tl_set:N = \l_tmpa_tl,
    underdblline / format .tl_set:N = \l_tmpa_tl,
    underwave    / format .tl_set:N = \l_tmpa_tl,
    sout         / format .tl_set:N = \l_tmpa_tl,
    xout         / format .tl_set:N = \l_tmpa_tl,
  }
\ExplSyntaxOff

@EthanDeng
Copy link
Member

根据群里的反馈,将 ams 系列的宏包挪到 ctex 宏包之前就没事了,已经将此修改应用到模板中。

这样会使英文字体变为 Latin Modern,见 xueruini/thuthesis#434 (comment)

ctex 下一个版本准备不再自动载入 (xe)CJKfntef 包,可以掩盖住问题。现在可以临时 hack 一下:

% 加在 \documentclass 之前
\RequirePackage{expl3}
\makeatletter
\@namedef{ver@xeCJKfntef.sty}{9999/99/99}
\makeatother
\ExplSyntaxOn
\keys_define:nn { xeCJK / options }
  {
    underdot     / format .tl_set:N = \l_tmpa_tl,
    underline    / format .tl_set:N = \l_tmpa_tl,
    underdblline / format .tl_set:N = \l_tmpa_tl,
    underwave    / format .tl_set:N = \l_tmpa_tl,
    sout         / format .tl_set:N = \l_tmpa_tl,
    xout         / format .tl_set:N = \l_tmpa_tl,
  }
\ExplSyntaxOff

因为 no-math 选项的引入,这个模板并没有这个问题。你可以测试下这个例子:

\PassOptionsToPackage{no-math}{fontspec}
\documentclass[12pt,a4paper]{article}

\usepackage{lipsum,zhlipsum}
\usepackage{amsmath,amssymb}
\usepackage[UTF8, scheme=plain]{ctex}

\usepackage{newtxtext}
\usepackage{newtxmath}

\begin{document}

\lipsum[1]
\zhlipsum[1]

\begin{equation}
\lvert x -y \rvert
\end{equation}

\end{document}

@stone-zeng
Copy link

好像是只要 amsmathctex 之前就可以了:

\documentclass{article}
\usepackage{amsmath}
\usepackage[scheme=chinese]{ctex}
\usepackage{newtxtext}
\usepackage{newtxmath}

\begin{document}
你好 Hello \LaTeX{}
\[ \int \sin x \mathrm{d} x = \alpha \]
\[ \lvert x -y \rvert \]
\end{document}

或者等价地:

\RequirePackage{amsmath}
\documentclass{ctexart}
\usepackage{newtxtext}
\usepackage{newtxmath}
...
`

@EthanDeng
Copy link
Member

嗯,调整顺序应该就行了。原来我记得好像不加 no-math 选项,xelatex 编译之后,数字是 Computer Modern,而不是 Times 风格。

\documentclass{article}

\usepackage{amsmath}
\usepackage[scheme=plain, UTF8]{ctex}
% newtx pkgs
\usepackage{newtxtext}
\usepackage{newtxmath}

\begin{document}

你好 Hello \LaTeX{}.
\begin{equation}
a^{2} + b^{2} = c^{2} \to i = 1, 2, \ldots, n
\end{equation}

\end{document}

编译结果:

example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants