TIKZ 与法国 Babel 之间的冲突

TIKZ 与法国 Babel 之间的冲突

可能重复:
tikz 声明函数和 babel 法语选项

我正在编写一份需要 tikz 和 [french]Babel 的文档。

[french]Babel 和 TIKZ 之间存在冲突:

  • 如果其中一个未加载则没有问题
  • 德语或意大利语没有问题
  • 西班牙语部分问题

该怎么办 ?

%!TEX TS-program = pdflatex
\PassOptionsToPackage{table,x11names,svgnames}{xcolor}

% ..............................................
% Expected behavior for language selection: (see original text, below, from Daniel Flipo):
%
%    The last language loaded is the main one, used in the TOC and other lists. 
%    Hence, if English is the last one loaded, we should expect to read "Contents", "Chapter 1", etc. 
%           If French is the last one loaded, we should see "Table des matières", "Chapitre 1"
%
% Ref:  " Documentation sur le module frenchb de Babel Daniel Flipo Version 2.5j – 27 décembre 2012"
%       La dernière langue chargée (le français dans l’exemple ci-dessus) est active au début du document ; c’est la langue principale, celle qui régit la présentation générale (listes, notes de bas de page, retrait des premiers paragraphes) quelle que soit la langue courante.
% ..............................................

% ..........................................................................................
% ......LANGUAGES TESTS: ENGLISH, FRENCH, SPANISH, ITALIAN, GERMAN / BEGINNING..........
%
%................  ENGLISH ............WORKS FINE......WITH OR WITHOUT [english] BABEL..........
%
%  \documentclass[10pt,twoside,openright,usletter,english]{book} % 
%  \usepackage[english]{babel} 
%
%................  FRENCH ............CRASHES.........CRASHES ONLY IF [FRENCH]BABEL LOADED.........
%
% .....Weird error as a result of a clash between Tikz and Babel/French..........
% .....No problem with the English or German or italian languages, partial problem with Spanish
% .....==>> if Tikz NOT loaded, then Babel / French:   works well.
%
%   \documentclass[10pt,twoside,openright,usletter,english,french]{book} % CRASHES ONLY IF [FRENCH]BABEL LOADED: " ! Argument of \tikz@next has an extra }  "
%
%  \documentclass[10pt,twoside,openright,usletter,french,english]{book} % CRASHES ONLY IF [FRENCH]BABEL LOADED: " ! Argument of \tikz@next has an extra }  "
%
  \documentclass[10pt,twoside,openright,usletter,french]{book}  % CRASHES PARTIALLY (SCROLLED MODE WORKS, but English is first language in Contents / Chapter) when [FRENCH]BABEL NOT LOADED: " ! Package babel Error: You haven't loaded the option english yet."  .......  IF [ENGLISH] BABEL or [ENGLISH,FRENCH] BABEL LOADED, crashes: " ! Argument of \tikz@next has an extra }." ......... 
%
   \usepackage[english,french]{babel} 
%   \usepackage[french]{babel} 
%
%................  SPANISH ...............WORKS PARTIALLY..........................
%
%  \documentclass[10pt,twoside,openright,usletter,spanish]{book}  % CRASHES PARTIALLY (SCROLLED MODE WORKS) when [spanish]Babel not loaded: ! Package babel Error: You haven't loaded the option english yet.
%  \usepackage[spanish]{babel}   % CRASHES PARTIALLY (SCROLLED MODE WORKS): " Cap\'{\i }tulo 1. ! Missing \endcsname inserted. <to be read again>  "
%   \usepackage[spanish,english]{babel}  % WORKS FINE, BUT English first (Contents, Chapter)
%  \usepackage[english,spanish]{babel}  % WORKS FINE, BUT English first (Contents, Chapter)
%   
%
%................  ITALIAN .............WORKS FINE.........WITH OR WITHOUT [italian] BABEL........
%
%   \documentclass[10pt,twoside,openright,usletter,english,italian]{book}  % WORKS / italian=first language
%   \documentclass[10pt,twoside,openright,usletter,italian,english]{book}  % WORKS / italian=first language
%   \usepackage[italian]{babel} 
%
%................  GERMAN ............WORKS FINE.........WITH OR WITHOUT [italian] BABEL..........
%
%   \documentclass[10pt,twoside,openright,usletter,english,german]{book} % WORKS / German=first language
%   \documentclass[10pt,twoside,openright,usletter,german,english]{book}  % WORKS / English=first language
%   \usepackage[german]{babel} 
%
% ..........................................................................................
% ......LANGUAGES TESTS: ENGLISH, FRENCH, SPANISH, ITALIAN, GERMAN / END..........
% ..........................................................................................



\usepackage{lipsum}

    \usepackage{eso-pic}
    \usepackage{tikz}
    \usetikzlibrary{positioning}  
    \usetikzlibrary{shapes}

\usepackage{hyperref}


\hypersetup{colorlinks=true,
         breaklinks=true,
         linkcolor=magenta,   
         bookmarks=true,
          pageanchor=true}     


    % Dimensions of tabs
    % Bloc dimensions étiquettes verticales à droite
    \newlength\HauteurOngletDroite   
    \setlength\HauteurOngletDroite{\dimexpr\paperheight/8\relax} %  
    \newlength\LargeurOngletDroite
    \setlength\LargeurOngletDroite{\dimexpr\paperwidth/33\relax} % 
    \newlength\ProfondeurTexteOngletDroite   
    \setlength\ProfondeurTexteOngletDroite{\dimexpr\LargeurOngletDroite/2-1.5mm\relax}
    \newlength\xOngletDroite  
    \setlength\xOngletDroite{\dimexpr\paperwidth-(\LargeurOngletDroite*1/2)\relax}
    \newlength\yOngletZeroDroite
    \newlength\yOngletUnDroite
    \setlength\yOngletZeroDroite{\dimexpr\paperheight-(\HauteurOngletDroite*1/2)\relax} %
    \setlength\yOngletUnDroite{\dimexpr\paperheight-(\HauteurOngletDroite*3/2)\relax}

    % style of tabs
    \tikzset{OngletDroite/.style={
    align=center,text width=\HauteurOngletDroite,text height=\LargeurOngletDroite,text depth=\ProfondeurTexteOngletDroite,inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=270,font=\sffamily\normalsize
    }}  % 



    % Newcommand for "My" side tabs
    \newcommand{\MesOnglets}{%     
    \begin{tikzpicture}[remember picture,overlay]  
        \coordinate (PositionOngletDroiteZero) at (\xOngletDroite,\yOngletZeroDroite) ;  
        \coordinate (PositionOngletDroiteUn) at (\xOngletDroite,\yOngletUnDroite) ; 
    % 
    \node (OngletDroiteZero)   at (PositionOngletDroiteZero)  {\hyperlink{HyperTableOfcontents}{\tikz
    \node[OngletDroite,draw=purple,fill=gray!20,text=green]{TDM};}};  
    % 
    \node (OngletDroiteUn)   at (PositionOngletDroiteUn)  {\hyperlink{HyperChapitreUn}{\tikz
    \node[OngletDroite,draw=blue,shade,top color=red, bottom color=green,shading angle=-30,text=red] {Chapitre 1};}};  
    \end{tikzpicture}
    }%   


    \AddToShipoutPicture{  
    \MesOnglets     % side tabs shipped out to every page
    }%  




\begin{document}


    \frontmatter 
    \hypertarget{HyperTableOfcontents}{\tableofcontents}

    \mainmatter

    \cleardoublepage
    \hypertarget{HyperChapitreUn}{\chapter{Chapitre un}}
    \section{Section un Chapitre un}

    \lipsum
    \section{Section deux Chapitre un}
    \lipsum

    \lipsum
    \lipsum

    \cleardoublepage
    \chapter{Chapitre deux}
    \lipsum
    \section{Section un Chapitre deux}
    \lipsum
    \section{Section deux Chapitre deux}
        \lipsum
    \lipsum
    \lipsum



\end{document}

答案1

抱歉,代码太多了,我会记住的。

非常感谢 egreg 提供的链接,以及 Babel / French 文档的作者 Daniel Flipo(电子邮件答复)。

Tikz 和 Babel/French 因对“;”的解释不同而发生冲突

有几种方法可以解决这个问题。

  • 第一(更简单的一个):

    代替

    \newcommand{\MesOnglets}{% \begin{tikzpicture}[记住图片,覆盖]

    \newcommand{\MesOnglets}{% \begin{tikzpicture}[记住图片,覆盖]\No​​AutoSpacing %

  • 第二个

    代替

    \newcommand{\MesOnglets}{% \begin{tikzpicture}[记住图片,覆盖]

    \newcommand{\MesOnglets}{% \begin{tikzpicture}[记住图片,覆盖]\shorthandoff{;} %

  • 第三个

    Philipp Lehman 的 etoolbox 包提供了一个工具来在 tikz 中本地化“;”的解释。要修复文档中的每个“tikzpicture”,只需添加以下两行,仅适用于法语版本:

    \usepackage{etoolbox} \AtBeginEnvironment{tikzpicture}{\shorthandoff{;}}

以下是我最终运行良好的代码:

%!TEX TS-program = pdflatex
\PassOptionsToPackage{table,x11names,svgnames}{xcolor}

%  Références:
%  http://tex.stackexchange.com/questions/29978/with-tipa-and-babels-ngerman-shorthandoff-in-a-macro
%  http://tex.stackexchange.com/questions/34670/babel-shorthand-doesnt-work-in-macros
%  http://tex.stackexchange.com/questions/86023/tikz-declare-function-and-babel-french-option
%
%   Solution de Daniel Flipo, auteur de la documentation Babel/français
%   C'est un problème bien connu de caractères « actifs » (le ; cette-fois). C'est traité dans la doc (section 5).
%   
%   Le plus simple est de remplacer
%      \newcommand{\MesOnglets}{%
%      \begin{tikzpicture}[remember picture,overlay]
%   par
%      \newcommand{\MesOnglets}{%
%      \begin{tikzpicture}[remember picture,overlay]\NoAutoSpacing % <=
%   ou seulement par
%      \newcommand{\MesOnglets}{%
%      \begin{tikzpicture}[remember picture,overlay]\shorthandoff{;} % <=


\documentclass[10pt,twoside,openright,usletter,french]{book}  
\usepackage{babel} % ordre de chargement tikz / babel ne change rien
\usepackage{lipsum}
\usepackage{eso-pic}
\usepackage{tikz}
\usetikzlibrary{positioning}  
\usetikzlibrary{shapes}



\usepackage{hyperref}


\hypersetup{colorlinks=true,
         breaklinks=true,
         linkcolor=magenta,   
         bookmarks=true,
          pageanchor=true}     

%---------

    % Bloc dimensions étiquettes verticales à droite
    \newlength\HauteurOngletDroite   
    \setlength\HauteurOngletDroite{\dimexpr\paperheight/8\relax} %  
    \newlength\LargeurOngletDroite
    \setlength\LargeurOngletDroite{\dimexpr\paperwidth/33\relax} % 
    \newlength\ProfondeurTexteOngletDroite   
    \setlength\ProfondeurTexteOngletDroite{\dimexpr\LargeurOngletDroite/2-1.5mm\relax}
    \newlength\xOngletDroite  
    \setlength\xOngletDroite{\dimexpr\paperwidth-(\LargeurOngletDroite*1/2)\relax}
    \newlength\yOngletZeroDroite
    \newlength\yOngletUnDroite
    \setlength\yOngletZeroDroite{\dimexpr\paperheight-(\HauteurOngletDroite*1/2)\relax} %
    \setlength\yOngletUnDroite{\dimexpr\paperheight-(\HauteurOngletDroite*3/2)\relax}

    % style of tabs
    \tikzset{OngletDroite/.style={
    align=center,text width=\HauteurOngletDroite,text height=\LargeurOngletDroite,text depth=\ProfondeurTexteOngletDroite,inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=270,font=\sffamily\normalsize
    }}  % 


    \newcommand{\MesOnglets}{%     
    \begin{tikzpicture}[remember picture,overlay]\NoAutoSpacing %  
        \coordinate (PositionOngletDroiteZero) at (\xOngletDroite,\yOngletZeroDroite) ;  
        \coordinate (PositionOngletDroiteUn) at (\xOngletDroite,\yOngletUnDroite) ; 
    % 
    \node (OngletDroiteZero)   at (PositionOngletDroiteZero)  {\hyperlink{HyperTableOfcontents}{\tikz
    \node[OngletDroite,draw=purple,fill=gray!20,text=green]{TDM};}};  
    % 
    \node (OngletDroiteUn)   at (PositionOngletDroiteUn)  {\hyperlink{HyperChapitreUn}{\tikz
    \node[OngletDroite,draw=blue,shade,top color=red, bottom color=green,shading angle=-30,text=red] {Chapitre 1};}};  
    \end{tikzpicture}
    }%   


    \AddToShipoutPicture{  
    \MesOnglets     % side tabs shipped out to every page
    }%  




    \begin{document}


    \frontmatter 
    \hypertarget{HyperTableOfcontents}{\tableofcontents}

    \mainmatter

    \cleardoublepage
    \hypertarget{HyperChapitreUn}{\chapter{Chapitre un}}
    \section{Section un Chapitre un}

    \lipsum
    \section{Section deux Chapitre un}
    \lipsum

    \lipsum
    \lipsum

    \cleardoublepage
    \chapter{Chapitre deux}
    \lipsum
    \section{Section un Chapitre deux}
    \lipsum
    \section{Section deux Chapitre deux}
        \lipsum
    \lipsum
    \lipsum
\end{document}

相关内容