我有两个文档,它们的前言相同,但出于某种原因,路径修饰在一个文档中有效,而在另一个文档中无效。Lualatex 一直抱怨这一点,! Undefined control sequence. <argument> \pgfdecoratedangle
我不知道为什么。无论我使用什么修饰,无论我将其应用于部分路径还是整个路径,它都只会显示该错误。
以下是完整文档:
% vim: ft=tex
\RequirePackage{luatex85,shellesc}
\documentclass{scrartcl}
%% I use KOMA-script as I find it gives total control over a document structure.
%% Memoir would probably achieve the same results with marginally less pain, but
%% I'm not entirely sure I want to spend the time learning the other major custom
%% page classes.
%% KOMA options
\KOMAoption{cleardoublepage}{empty}
\KOMAoption{DIV}{10}
\KOMAoption{draft}{false}
\KOMAoption{fontsize}{10pt}
\KOMAoption{headings}{small}
% \KOMAoption{open}{right}
\KOMAoption{paper}{a4}
\KOMAoption{parskip}{half}
\KOMAoption{twoside}{false}
\KOMAoption{captions}{signature}
\KOMAoption{titlepage}{false}
\KOMAoption{abstract}{false}
\usepackage{listings}
%% e-TeX tools
\usepackage{etoolbox}
%% Subfiles for shared preambles
\usepackage{subfiles}
\usepackage{polyglossia}
\setdefaultlanguage[variant=australian]{english}
%% Colours - put this before typography so additional named colours can be defined.
\usepackage[table]{xcolor}
\definecolor{rmitred}{HTML}{DC241F}
\definecolor{rmitblue}{HTML}{341FDC}
\definecolor{red}{HTML}{DC291E}
\definecolor{blue}{HTML}{04588A}
\definecolor{orange}{HTML}{FA6B00}
\definecolor{green}{HTML}{038130}
\colorlet{wood}{brown!80!gray}
\colorlet{steel}{blue!20!gray}
\colorlet{tabledarkrow}{gray!12.5}
% \colorlet{tablelightrow}{gray!0}
%% Typography Settings
\usepackage[protrusion,expansion]{microtype}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\usepackage{xunicode}
% xltxtra is not used with LuaTeX
% \usepackage{xltxtra}
%% Maths typography — re-enable these if we need maths support
\usepackage{physics}
\usepackage{mathtools}
\usepackage{unicode-math}
%% Use this to set up the headers and footers in the pages later on.
%% Note that I will need to rework the code for that, as \makeatletter is ugly
\setkomafont{pagehead}{\small\sffamily\color{red}\selectfont}
\setkomafont{pagenumber}{\small\sffamily\color{black}\selectfont}
\usepackage[automark,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\lohead{\thetitle}
\rohead{\theauthor}
\cfoot{\pagemark}
\setkomafont{title}{\Huge\sffamily\bfseries\color{red}}
\setkomafont{titlehead}{\color{gray}\large\sffamily}
\setkomafont{author}{\small\itshape}
\setkomafont{publishers}{\usefontofkomafont{author}}
\setkomafont{date}{\small}
\setkomafont{disposition}{\sffamily}
\setkomafont{section}{\sffamily\Large\bfseries}
\setkomafont{subsection}{\sffamily\large\bfseries}
\setkomafont{subsubsection}{\sffamily\bfseries}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
\renewcommand{\sup}[1]{\textsuperscript{#1}}
\newcommand{\sub}[1]{\textsubscript{#1}}
% \usepackage{standalone}
\usepackage{tikz}
% \usepackage{pgfplots}
% \usepackage{pgfplotstable}
% \pgfplotsset{compat=1.13}
% Lua math library seems to clash with tikz decorations
\usepgflibrary{luamath}
\pgfkeys{pgf/luamath=parser}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}
\usetikzlibrary{external}
\usetikzlibrary{patterns}
\usepgflibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{angles}
% \tikzexternalize[prefix=tikz/,shell escape=-enable-write18]
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
\tikzset{
% Defines a custom style which generates BOTH, .pdf and .png export
% but prefers the .png on inclusion.
%
% This style is not pre-defined, you may need to copy-paste and
% adjust it.
png export/.style={%
external/system call/.add=%
{}
; convert -density 300 -transparent white "\image.pdf" "\image.png",
},
png images/.style={%
external/system call/.add=%
{}
; convert -density 300 -transparent white "\image.pdf" "\image.png",
% Don't need this as we're keeping the PDF in the document
/pgf/images/external info,
/pgf/images/include external/.code={%
\includegraphics
[width=\pgfexternalwidth,height=\pgfexternalheight]
{##1.png}%
},
}
}
\usepackage{siunitx}
\usepackage{cancel}
\sisetup{detect-all, per-mode=symbol}
\DeclareSIPostPower\fourth{4}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\makeatletter
\newlength{\questionbeforeskip}
\newlength{\questionafterskip}
\setlength{\questionbeforeskip}{1.0ex plus -1ex minus -0.25ex}
\setlength{\questionafterskip}{1ex plus 0.25ex}
\newlength{\answerskip}
\setlength{\answerskip}{0.25ex plus -0.125ex minus -0.125ex}
\addtotoclist{loq}
\newcommand{\listofloqname}{List of Questions}
\newcommand{\listofquestions}{\listoftoc{loq}}
\setuptoc{loq}{sectionatlist}
\newcounter{question}[section]
\newcommand{\questionautorefname}{question}
\DeclareRobustCommand{\question}[2]{%
\refstepcounter{question}%
\addxcontentsline{loq}{section}{Question~#1}
\pdfbookmark{Question~#1}{question:\thesection.\thequestion}
{\usekomafont{subsection}{\par\vspace\questionbeforeskip Question~#1.}\par}
{\itshape #2}\par\vspace\questionafterskip
}%
\newcommand{\answer}{\par\vspace\answerskip{\usekomafont{subsubsection}{Answer}}\par\vspace\answerskip}
\def\toclevel@question{4}
\makeatother
\usepackage[inline]{enumitem}
\setlist[enumerate]{label=(\alph*)}
% \setlist{noitemsep}
% \setlist[1]{labelindent=\parindent}
\newlist{subquestions}{enumerate}{3}
\setlist[subquestions]{leftmargin=*}
\setlist[subquestions,1]{label=\textup{\textbf{(\alph*)}}}
% Inline subquestions
\newlist{subquestions*}{enumerate*}{3}
\setlist[subquestions*]{itemjoin*={{, and }}}
\setlist[subquestions*,1]{label=\textup{\textbf{(\alph*)}}}
\newcommand{\qitem}[1]{\item{\textit{#1}}}
\newcommand{\qitemp}[1]{\qitem{#1}\\[0.5\parskip]}
\newcommand{\qitemq}[1]{\qitem{#1}\quad}
\usepackage{array}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{booktabs}
\newcolumntype{F}{>{\global\let\currentrowstyle\empty}}
\newcolumntype{f}{>{\currentrowstyle}X}
\newcolumntype{-}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
% DEPRECATED
% TODO Find this in all documents and remove it
\newcommand{\SetRowStyle}[1]{\rowstyle #1}
% \newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{B}{>{\bfseries}} % Bold
\newcolumntype{K}{>{\scshape}} % Smallcaps (German Kapitälchen)
\newcolumntype{I}{>{\itshape}} % Italics
\newcolumntype{w}{<{\hspace{0.75em}}} % Wide column
\renewcommand{\arraystretch}{1.25}
\renewcommand{\tabcolsep}{0.5em}
\usepackage{floatrow}
%% Penalties
\hyphenpenalty=2500
\tolerance=500
\widowpenalty=1500
\clubpenalty=1500
% Metadata goes here
\titlehead{A University}
\subject{The Subject}
\title{Homework 1}
\author{The Author}
\date{\today}
\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother
\usepackage{hyperref}
\hypersetup{
pdfauthor={The Author},
pdftitle={Homework 1},
colorlinks=false,
hidelinks}
\usepackage[all]{hypcap}
%% Define all TikZ styles here
\tikzset{%
information text/.style={xshift=0.30\textwidth, every node/.style={right, text width=0.70\textwidth, inner sep=1ex}},
%
my axes/.style={node font=\small, every node/.style={fill=white, fill opacity=0.0, text opacity=1}},
important line/.style={very thick},
cross section/.style={draw, line width=0.5pt, blue, fill=blue!40!white, every node/.style={node font=\footnotesize, color=black}},
shape outline/.style={draw, line width=0.5pt, blue, fill=blue!20!white, every node/.style={node font=\footnotesize, color=black}},
segment boundary/.style={draw, line width=0.5pt, dashed},
dim edge/.style={densely dashed, line width=0.5pt, shorten >= -2.5mm, color=black!75!white},
dim length/.style={draw, line width=0.5pt, arrows={Stealth-Stealth}, every node/.style={anchor=mid, midway, fill=white, node font=\footnotesize, inner sep=1pt},
},
translucent node/.style={fill opacity=0.5, text opacity=1},
translucent shape/.style={fill opacity=0.75},
rough edge/.style={decorate, decoration={random steps, segment length=2mm, amplitude=0.5mm}},
% rough edge/.style={decorate, decoration={zigzag}},
label/.style={every node/.style={anchor=mid, midway, inner sep=2pt, circle, fill=white, fill opacity=0.375, text opacity=1}},
% png export,
}
\begin{document}
\maketitle
\question{6--20}{Locate the centroid $(\bar x, \bar y)$ for the angle's cross-sectional area:}
\begin{center}
% \tikzexternaldisable
\tikzsetnextfilename{homework-1-6-20}
\begin{tikzpicture}
\begin{scope}[my axes]
\draw[->] (0, 0) -- (6, 0) node[right] {$x$} coordinate(x axis);
\draw[->] (0, 0) -- (0, 5) node[above] {$y$} coordinate(y axis);
\end{scope}
\fill [fill=green!50!white]
(0, 0) -- (4, 0) -- (4, 1) -- (1, 1) -- (1, 3) -- (0, 3) -- cycle;
\path [fill=green!35!white]
decorate[rough edge]{(0.75, 4) -- (1.75, 4)} -- (1, 3) -- (0, 3) -- cycle
decorate[rough edge]{(1.75, 2) -- (4.75, 2)} -- (4, 1) -- (1, 1) -- cycle;
\fill [fill=green!65!white]
decorate[rough edge]{(1.75, 4) -- (1.75, 2)} -- (1, 1) -- (1, 3) -- cycle;
\fill [fill=green!65!white]
decorate[rough edge]{(4.75, 2) -- (4.75, 1)} -- (4, 0) -- (4, 1) -- cycle;
\draw [green!10!white, line width=0.5pt]
(0, 3) -- (1, 3) -- (1, 1) -- (4, 1) -- (4.75, 2)
(1, 3) -- (1.75, 4)
(4, 0) -- (4, 1);
\draw [green, line width=0.5pt]
(0.75, 4) -- (0, 3) -- (0, 0) -- (4, 0) -- (4.75, 1)
(1, 0) -- (1, 1) -- (1.75, 2);
\begin{scope}[my axes]
\draw[->] (1.5, 1.9) -- (6, 1.9) node[right] {$x'$};
\draw[->] (1.5, 1.9) -- (1.5, 5) node[above] {$y'$};
\fill (1.5, 1.9) circle [radius=0.5mm];
\node at (1.75, 2.15) {$C$};
\end{scope}
\path[label] (0, 0) -- (1, 3) node {1};
\path[label] (1, 0) -- (4, 1) node {2};
\draw[dim edge] (0, 0) -- (-0.5, 0);
\draw[dim edge] (0, 3) -- (-0.5, 3);
\draw[dim length] (-0.5, 0) -- (-0.5, 3) node {150};
\draw[dim edge] (0, 0) -- (0, -0.5);
\draw[dim edge] (1, 0) -- (1, -0.5);
\draw[dim edge] (4, 0) -- (4, -0.5);
\draw[dim length] (0, -0.5) -- (1, -0.5) node {50};
\draw[dim length] (1, -0.5) -- (4, -0.5) node {150};
\draw[dim edge] (4, 1) -- (5, 1);
\draw[dim length] (5, 0) -- (5, 1) node {50};
\draw[dim length] (5.5, 0) -- (5.5, 1.9) node {$\bar y$};
\draw[dim length] (0, 4.5) -- (1.5, 4.5) node {$\bar x$};
\node[above right, text width=3cm, node font=\itshape\small] at (2.5, 2.5) {All dimensions in \si{\mm}};
\end{tikzpicture}
\end{center}
\answer
Divide the area into its composite shapes.
\begin{equation*}
\begin{array}{l l l l l l}
\toprule
\text{Segment} & \text{Area} & \tilde x & \tilde y & \tilde x A & \tilde y A \\
\midrule
\multirow{2}{*}{1}
& 50 × 150 & \tfrac{1}{2} × 50
& \tfrac{1}{2} × 150
& 7500 × 25
& 7500 × 75 \\
& =\SI{7500}{\square\mm}
& =\SI{25}{\mm}
& =\SI{75}{\mm}
& =\SI{187500}{\cubic\mm}
& =\SI{562500}{\cubic\mm} \\[0.75\parskip]
\multirow{2}{*}{2}
& 50 × 150
& \tfrac{1}{2} × 150 + 50
& \tfrac{1}{2} × 50
& 7500 × 125
& 7500 × 25 \\
& =\SI{7500}{\square\mm}
& =\SI{125}{\mm}
& =\SI{25}{\mm}
& =\SI{937500}{\cubic\mm}
& =\SI{187500}{\cubic\mm}\\
\midrule
\sum & = \SI{15000}{\square\mm} &&& = \SI{1125000}{\mm\cubed} & = \SI{750000}{\mm\cubed} \\
\bottomrule
\end{array}
\end{equation*}
\begin{align*}
\bar x &= \frac{\sum \tilde x A}{\sum A} = \frac{\SI{1125000}{\mm\cubed}}{\SI{15000}{\mm\squared}} = \SI{75}{\mm} \\[\parskip]
\bar y &= \frac{\sum \tilde y A}{\sum A} = \frac{\SI{750000}{\mm\cubed}}{\SI{15000}{\mm\squared}} = \SI{50}{\mm}
\end{align*}
\end{document}
文档开始之前的命令tikzset
用于配置我在多个单独的绘图中使用的全局 TikZ 样式。
奇怪的是,删除luamath
解析器可以在行为错误的文档中修复它,但这并不能解释为什么它在工作文档中起作用。
编辑以下是完整文档的截断部分的链接: https://gist.github.com/zoqaeski/df78b4eadbb4f351db49750b2451df25
平均能量损失
% emacs: ft=tex
\RequirePackage{luatex85,shellesc}
\documentclass{article}
\usepackage{tikz}
\ifx\directlua\undefined\else
% Lua math library seems to clash with tikz decorations
\usepgflibrary{luamath}
\pgfkeys{pgf/luamath=parser}
\fi
\usetikzlibrary{decorations.pathmorphing}
\makeatother
%% Define all TikZ styles here
\tikzset{%
rough edge/.style={decorate, decoration={random steps, segment length=2mm, amplitude=0.5mm}},
}
\begin{document}
\begin{tikzpicture}
\path [fill=green!35!white]
decorate[rough edge]{(0.75, 4) -- (1.75, 4)} -- (1, 3) -- (0, 3) -- cycle;
\end{tikzpicture}
\end{document}
答案1
至少在我的计算机上,添加这些行可以解决问题
\makeatletter
\def\pgfmathanglebetweenpoints#1#2{%
\begingroup%
\pgf@process{\pgfpointdiff{#1}{#2}}%
\edef\pgf@marshall{\expandafter\noexpand\csname pgfmathatan2@\endcsname{\expandafter\Pgf@geT\the\pgf@y}{\expandafter\Pgf@geT\the\pgf@x}}%
\pgf@marshall%
\ifdim\pgfmathresult pt<0pt\relax% <-- All I added is this this \relax
\pgfmathparse{\pgfmathresult+360}%
\fi%
\expandafter%
\endgroup\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult}%
}
看来,如果没有\relax
,TeX 将尝试读取下一个标记\pgfmathparse
,然后在一些奇怪的扩展之后,与之对应的标记\fi
从未\ifdim
被读取过。
然后 TeX 回到上一个宏扩展,即\pgf@decorate@processnextinputsegmentobject
。由于有很多\fi
,TeX 将采用其中一个,到目前为止不会报告任何错误。
过了一会儿,TeX 想要使用 的值\pgfdecoratedangle
,而该值应该由 定义\let\pgfdecoratedangle\pgfmathparse
。但是 TeX 在找到 时忽略了该定义\fi
,因此出现了未定义的控制序列错误。