Tikz-UML 类名中的 UTF-8

Tikz-UML 类名中的 UTF-8

我在 TikZ-UML 中的类名中使用 UTF-8 字符时遇到问题。

该代码有效:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{tikz-uml}

\begin{document}
\begin{tikzpicture}
\umlsimpleclass{classname}
\end{tikzpicture}
\end{document}

但是,将字符更改为 UTF-8 字符(如 é 或 ø)会导致错误Missing \endcsname inserted.

像这样:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{tikz-uml}

\begin{document}
\begin{tikzpicture}
\umlsimpleclass{classnamé}
\end{tikzpicture}
\end{document}

这可能与以下情​​况有关:tikz UML 和重音符号的问题但是,该解决方案并不能解决问题\umlsimpleclass

答案1

这或多或少是同样的问题,但需要匹配不同的地方。

在此处输入图片描述

我更换了

  \def\tikzumlClassName{#2}%

经过

  \def\tikzumlClassName{\detokenize{#2}}%
  \def\tikzumlClassNameB{#2}%

然后使用版本仅在排版的地方(特别是\textbf{\tikzumlClassName}我将所有实例更改为\textbf{\tikzumlClassNameB}

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{tikz-uml}
\errorcontextlines1000


\makeatletter
\renewcommand{\umlclass}[4][]{%
  \pgfkeys{/tikzuml/class/.cd, x/.initial=\tikzumlDefaultX, y/.initial=\tikzumlDefaultX, width/.initial=\tikzumlClassDefaultWidth, type/.initial=\tikzumlClassDefaultType,%
                               tags/.initial={}, style/.style={},%
                               template/.initial={}, name/.initial=tikzumlEmpty,%
                               draw/.initial=\tikzumlDefaultDrawColor,%
                               fill template/.initial=\tikzumlClassTemplateFillColorDefaultFillColor,%
                               fill/.initial=\tikzumlClassDefaultFillColor,%
                               text/.initial=\tikzumlDefaultTextColor,%
                               simple/.is if=tikzumlclassSimpleStyle, circle/.is if=tikzumlclassCircleShape, no coords/.is if=tikzumlclassWithoutCoords,%
                               simple=false, circle=false, no coords=false,%
                               .unknown/.code={%
                                 \let\keyname=\pgfkeyscurrentname%
                                 \let\keyvalue=\pgfkeyscurrentvalue%
                                 \ifthenelse{\equal{\keyname}{above}\OR%
                                             \equal{\keyname}{left}\OR%
                                             \equal{\keyname}{below}\OR%
                                             \equal{\keyname}{right}\OR%
                                             \equal{\keyname}{above left}\OR%
                                             \equal{\keyname}{above right}\OR%
                                             \equal{\keyname}{below left}\OR%
                                             \equal{\keyname}{below right}}{%
                                   \IfSubStr{\keyvalue}{ of }{%
                                     \pgfkeys{/tikzuml/class/.cd, no coords}%
                                   }{}%
                                 }{}%
                                 \ifx\keyvalue\pgfkeysnovalue%
                                   \pgfkeys{/tikzuml/class/.cd, style/.append style/.expand once={\keyname}}%
                                 \else%
                                   \pgfkeys{/tikzuml/class/.cd, style/.append style/.expand twice={\expandafter\keyname\expandafter=\keyvalue}}%
                                 \fi%
                                 %\errmessage{TIKZUML ERROR : in umlclass, invalid option \keyname}%
                               }%
  }%
  \pgfkeys{/tikzuml/class/.cd,#1}%
  %
  \iftikzumlclassSimpleStyle%
    \iftikzumlclassCircleShape%
      \pgfkeys{/tikzuml/class/.cd, width/.initial=\tikzumlSimpleInterfaceDefaultWidth}%
    \fi%
  \fi%
  %
  \pgfkeys{/tikzuml/class/.cd, x/.get=\tikzumlClassX, y/.get=\tikzumlClassY, width/.get=\tikzumlClassMinimumWidth,% 
                               type/.get=\tikzumlClassTypeTmp, tags/.get=\tikzumlClassTagsTmp, template/.get=\tikzumlClassTemplateFillColorParam,%
                               name/.get=\tikzumlClassName,%
                               draw/.get=\tikzumlClassDrawColor, fill/.get=\tikzumlClassFillColor,%
                               text/.get=\tikzumlClassTextColor, fill template/.get=\tikzumlClassTemplateFillColor%
  }%
  %
  \ifthenelse{\equal{\tikzumlClassTypeTmp}{class}\OR\equal{\tikzumlClassTypeTmp}{abstract}}{%
    \def\tikzumlClassType{}%
  }{%
    \expandafter\def\expandafter\tikzumlClassType\expandafter{$\ll$\tikzumlClassTypeTmp$\gg$ \\}%
  }%
  %
  \ifthenelse{\equal{\tikzumlClassTagsTmp}{}}{%
    \def\tikzumlClassTags{}%
  }{%
    \def\tikzumlClassTags{\\ \{\tikzumlClassTagsTmp\}}%
  }%
  %
  \ifthenelse{\equal{\tikzumlClassTemplateFillColorParam}{}}{%
    \def\tikzumlClassVPadding{}%
    \def\tikzumlClassHPadding{}%
  }{%
    \def\tikzumlClassVPadding{\vspace{0.1em} \\}%
    \def\tikzumlClassHPadding{\hspace{0.5ex} $ $}%
  }%
  %
  \def\tikzumlClassName{\detokenize{#2}}%
  \def\tikzumlClassNameB{#2}%
  %
  \begingroup%
    \def\_{_}\edef\x{\endgroup%
      \def\noexpand\tikzumlClassNodeName{\tikzumlClassName}}\x%
  %
  \ifthenelse{\equal{\tikzumlClassName}{tikzumlEmpty}}{}{%
    \def\tikzumlClassNodeName{\tikzumlClassName}%
  }%
  %
  \StrSubstitute{\tikzumlClassNodeName}{:}{@COLON@}[\tikzumlClassNodeName]%
  \StrSubstitute{\tikzumlClassNodeName}{\_}{@UNDERSCORE@}[\tikzumlClassNodeName]%
  %
  \ifthenelse{\equal{\tikzumlClassTypeTmp}{abstract}}{%
    \let\tikzumlClassNameOld\tikzumlClassName%
    \def\tikzumlClassName{{\it \tikzumlClassNameOld}}%
  }{}%
  %
  \def\tikzumlClassPos{\tikzumlClassX,\tikzumlClassY}%
  \def\tikzumlClassAttributes{#3}%
  \def\tikzumlClassOperations{#4}%
  %
  \iftikzumlclassSimpleStyle%
    \iftikzumlclassWithoutCoords%
      \iftikzumlclassCircleShape%
        \node[tikzuml simpleinterface style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) {};%
        \node[anchor=south] (\tikzumlClassNodeName-label) at (\tikzumlClassNodeName.north) {\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassNameB} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
        };%
      \else%
        \node[tikzuml simpleclass style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) {\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassNameB} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
        };%
      \fi%
    \else%
      \iftikzumlclassCircleShape%
        \node[tikzuml simpleinterface style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) at (\tikzumlClassPos) {};
        \node[anchor=south] (\tikzumlClassNodeName-label) at (\tikzumlClassNodeName.north){\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassNameB} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
        };%
      \else%
        \node[tikzuml simpleclass style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) at (\tikzumlClassPos) {\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassNameB} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
        };%
      \fi%
    \fi%
  \else%
    \iftikzumlclassWithoutCoords%
      \node[tikzuml class style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) {\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassNameB} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
      \nodepart{second}%
      \begin{tabular}{l}%
      \tikzumlClassAttributes%
      \end{tabular}%
      \nodepart{third}%
      \begin{tabular}{l}%
      \tikzumlClassOperations%
      \end{tabular}%
      };%
    \else%
      \node[tikzuml class style, draw=\tikzumlClassDrawColor, fill=\tikzumlClassFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont, minimum width=\tikzumlClassMinimumWidth, /tikzuml/class/style] (\tikzumlClassNodeName) at (\tikzumlClassPos) {\begin{tabular}{c}\tikzumlClassVPadding \tikzumlClassType \tikzumlClassHPadding \textbf{\tikzumlClassName} \tikzumlClassHPadding \tikzumlClassTags \end{tabular}%
      \nodepart{second}%
      \begin{tabular}{l}%
      \tikzumlClassAttributes%
      \end{tabular}%
      \nodepart{third}%
      \begin{tabular}{l}%
      \tikzumlClassOperations%
      \end{tabular}%
      };%
    \fi%
  \fi%
  %
  \ifthenelse{\equal{\tikzumlClassTemplateFillColorParam}{}}{}{%
    \draw (\tikzumlClassNodeName.north east) node[tikzuml template style, name=\tikzumlClassNodeName-template, draw=\tikzumlClassDrawColor, fill=\tikzumlClassTemplateFillColor, text=\tikzumlClassTextColor, font=\tikzumlDefaultFont] {\tikzumlClassTemplateFillColorParam};%
  }%
  %
  % add to fit
  \ifnum\c@tikzumlPackageLevel>0%
    \edef\tikzumlPackageFitOld{\csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname}%
    \ifthenelse{\equal{\tikzumlClassTemplateFillColorParam}{}}{%
      \expandafter\xdef\csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname{\tikzumlPackageFitOld (\tikzumlClassNodeName)}%
    }{%
      \expandafter\xdef\csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname{\tikzumlPackageFitOld (\tikzumlClassNodeName) (\tikzumlClassNodeName-template)}%
    }%
    \stepcounter{tikzumlPackageClassNum}%
  \fi%
  \ifnum\c@tikzumlComponentLevel>0%
    \def\tikzumlComponentFitTmp{\csname tikzumlComponentFit\tikzumlComponent@parent @@\tikzumlComponent@fitname\endcsname}%
    \ifthenelse{\equal{\tikzumlClassTemplateFillColorParam}{}}{%
      \expandafter\xdef\csname tikzumlComponentFit\tikzumlComponent@parent @@\tikzumlComponent@fitname\endcsname{\tikzumlComponentFitTmp (\tikzumlClassNodeName)}%
    }{%
      \expandafter\xdef\csname tikzumlComponentFit\tikzumlComponent@parent @@\tikzumlComponent@fitname\endcsname{\tikzumlComponentFitTmp (\tikzumlClassNodeName) (\tikzumlClassNodeName-template)}%
    }%
    \stepcounter{tikzumlComponentSubComponentNum}%
  \fi%
}%
\makeatletter
\begin{document}
\begin{tikzpicture}

\umlsimpleclass{classnamé}
\end{tikzpicture}
\end{document}

相关内容