我正在尝试为一个项目创建引文中的自定义后记,我需要巧妙地突出一些引文。我想画两个半圆,用不同的颜色填充,并将其显示为引文旁边的后记。以下是我正在尝试的 MWE:
\documentclass[a4paper,BCOR=0mm,DIV=18]{scrartcl}
\usepackage{xcolor}
\definecolor{mygreen}{rgb}{0.106,0.62,0.467}
\definecolor{myorange}{rgb}{0.851,0.373,0.008}
\usepackage[backend=biber]{biblatex}
\addbibresource{temp.bib}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\mix}{{
\begin{tikzpicture}
\begin{scope}
\clip (0,-0.5ex) rectangle (0.5ex,0.5ex);
\fill[myorange] (0,0) circle(0.5ex);
\draw[myorange] (0,-0.5ex) -- (0,0.5ex);
\end{scope}
\begin{scope}
\clip (0,0.5ex) rectangle (-0.5ex,-0.5ex);
\fill[mygreen] (0,0) circle(0.5ex);
\end{scope}
\end{tikzpicture}}}
\begin{document}
Why does this citation \cite[\mix]{ref} not work? % comment to get it to run
But this \mix works?
\end{document}
和参考书目文件:
@article{ref,
title = {blah blah},
journaltitle = {Journal},
}
当我把命令放在\mix
外面时\cite
,一切都正常,但是一旦我将它用作后记,我就会undefined control sequence
在整个节目中收到错误...有人知道我该如何解决这个问题吗?
答案1
这不是你问题的真正答案,为什么放置 Ti钾宏内的 Z 代码\cite
不起作用,但可以快速修复:使用保存框。我还稍微简化了图标的代码。
\documentclass[a4paper,BCOR=0mm,DIV=18]{scrartcl}
\begin{filecontents}{temp.bib}
@article{ref,
title = {blah blah},
journaltitle = {Journal},
}
\end{filecontents}
\usepackage{xcolor}
\definecolor{mygreen}{rgb}{0.106,0.62,0.467}
\definecolor{myorange}{rgb}{0.851,0.373,0.008}
\usepackage[backend=biber]{biblatex}
\addbibresource{temp.bib}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newsavebox{\mix}
\savebox{\mix}{%
\begin{tikzpicture}
\fill[myorange] (0,-0.5ex) arc[start angle=-90, end angle=90, radius=0.5ex] -- cycle;
\fill[mygreen] (0,0.5ex) arc[start angle=90, end angle=270, radius=0.5ex] -- cycle;
\end{tikzpicture}%
}
\begin{document}
Why does this citation \cite[\usebox{\mix}]{ref} not work?
But this \usebox{\mix} works?
\end{document}
答案2
宏\mix
需要受保护,所以你需要写
\cite[\protect\mix]{ref}
但这样做会很繁琐。LaTeX 还提供了一种方法来定义要保护的宏(“健壮”):
\DeclareRobustCommand*{\mix}{% ← % important to hide space
\begin{tikzpicture}[radius=.5ex,delta angle=180]
\fill[myorange](up:.5ex)arc[start angle=90];
\fill[mygreen](down:.5ex)arc[start angle=270];
\end{tikzpicture}}
也就是说,如果你经常使用该图片,最好将其保存在一个盒子里,这样就不需要一遍又一遍地计算。
您也可以在standalone
文档中创建它一次,然后将其保存为微型 PDF,然后将其保存\includegraphics
在您的文档中。
代码
\begin{filecontents*}{\jobname.bib}
@article{ref,
title = {blah blah},
journaltitle = {Journal},
}
\end{filecontents*}
\documentclass[a4paper,BCOR=0mm,DIV=18]{scrartcl}
\usepackage{tikz}
\definecolor{mygreen}{rgb}{0.106,0.62,0.467}
\definecolor{myorange}{rgb}{0.851,0.373,0.008}
\usepackage[backend=biber]{biblatex}
\addbibresource{\jobname.bib}
\DeclareRobustCommand*{\mix}{% ← % important to hide space
\begin{tikzpicture}[radius=.5ex,delta angle=180]
\fill[myorange](up:.5ex)arc[start angle=90];
\fill[mygreen](down:.5ex)arc[start angle=270];
\end{tikzpicture}}
\begin{document}
Why does this citation \cite[\mix]{ref} not work?
But this \mix\ works?
\end{document}