问题更新

问题更新

由于向后兼容,我希望让包接受两种指定某些文本字体大小的方式。理想情况下,我应该能够将其指定为\todo[size=\tiny]{test}\todo[size=tiny]{test}(\tiny vs tiny)。

我可以编译以下示例并生成预期的输出。但它在编译过程中引发多个错误(! Missing \endcsname inserted.)。我该如何摆脱这些编译错误?

输入如下:

\documentclass{article}
\listfiles
\usepackage{tikz}

\begin{document}

\newcommand{\commandfromtext}{\csname tiny\endcsname}
\newcommand{\commandfromfontcommand}{\csname \tiny\endcsname}
\newcommand{\directcommand}{\tiny}

\begin{tikzpicture}
\draw (0, 0) rectangle (5, 4);
\draw[opacity=0.5] (2, 0.5) node[]{Test 1};
\draw[opacity=0.5] (2, 1.0) node[font=\tiny]{Test 2};
\draw[opacity=0.5] (2, 1.5) node[font=\csname tiny\endcsname]{Test 3};
\draw[opacity=0.5] (2, 2.0) node[font=\commandfromtext]{Test 4};
\draw[opacity=0.5] (2, 2.5) node[font=\directcommand]{Test 5};
\draw[opacity=0.5] (2, 3.0) node[font=\commandfromfontcommand]{Test 6};
\draw[opacity=0.5] (2, 3.5) node[font=\csname \tiny\endcsname]{Test 7};
\end{tikzpicture}

\end{document}

生成输出

在此处输入图片描述

编译期间会引发以下错误

! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.18 ..., 3.0) node[font=\commandfromfontcommand]{
                                                  Test 6};
? R
OK, entering \nonstopmode...
! Extra \endcsname.
\commandfromfontcommand ...sname \tiny \endcsname 

l.18 ..., 3.0) node[font=\commandfromfontcommand]{
                                                  Test 6};
! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.19 ..., 3.5) node[font=\csname \tiny\endcsname]{
                                                  Test 7};
! Extra \endcsname.
\tikz@textfont ->\csname \tiny \endcsname 

l.19 ..., 3.5) node[font=\csname \tiny\endcsname]{
                                                  Test 7};

日志文件包含以下信息

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.10.15)  15 OCT 2018 10:19
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**csnameuserissue.tex
(./csnameuserissue.tex
LaTeX2e <2018-04-01> patch level 5
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
\pgfutil@everybye=\toks14
\pgfutil@tempdima=\dimen103
\pgfutil@tempdimb=\dimen104

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
\pgfutil@abb=\box26
(/usr/local/texlive/2018/texmf-dist/tex/latex/ms/everyshi.sty
Package: everyshi 2001/05/15 v3.00 EveryShipout Package (MS)
))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
Package: pgfrcs 2015/08/07 v3.0.1a (rcs-revision 1.31)
))
Package: pgf 2015/08/07 v3.0.1a (rcs-revision 1.15)
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 99.

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/pdftex.def
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
))
\Gin@req@height=\dimen105
\Gin@req@width=\dimen106
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
Package: pgfsys 2014/07/09 v3.0.1a (rcs-revision 1.48)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
\pgfkeys@pathtoks=\toks16
\pgfkeys@temptoks=\toks17

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c
ode.tex
\pgfkeys@tmptoks=\toks18
))
\pgf@x=\dimen107
\pgf@y=\dimen108
\pgf@xa=\dimen109
\pgf@ya=\dimen110
\pgf@xb=\dimen111
\pgf@yb=\dimen112
\pgf@xc=\dimen113
\pgf@yc=\dimen114
\w@pgf@writea=\write3
\r@pgf@reada=\read1
\c@pgf@counta=\count88
\c@pgf@countb=\count89
\c@pgf@countc=\count90
\c@pgf@countd=\count91
\t@pgf@toka=\toks19
\t@pgf@tokb=\toks20
\t@pgf@tokc=\toks21

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg
File: pgf.cfg 2008/05/14  (rcs-revision 1.7)
)
Driver file for pgf: pgfsys-pdftex.def

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.d
ef
File: pgfsys-pdftex.def 2014/10/11  (rcs-revision 1.35)

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p
df.def
File: pgfsys-common-pdf.def 2013/10/10  (rcs-revision 1.13)
)))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.
code.tex
File: pgfsyssoftpath.code.tex 2013/09/09  (rcs-revision 1.9)
\pgfsyssoftpath@smallbuffer@items=\count92
\pgfsyssoftpath@bigbuffer@items=\count93
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.
code.tex
File: pgfsysprotocol.code.tex 2006/10/16  (rcs-revision 1.4)
)) (/usr/local/texlive/2018/texmf-dist/tex/latex/xcolor/xcolor.sty
Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/color.cfg
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package xcolor Info: Driver file: pdftex.def on input line 225.
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
Package xcolor Info: Model `RGB' extended on input line 1364.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
Package: pgfcore 2010/04/11 v3.0.1a (rcs-revision 1.7)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
\pgfmath@dimen=\dimen115
\pgfmath@count=\count94
\pgfmath@box=\box27
\pgfmath@toks=\toks22
\pgfmath@stack@operand=\toks23
\pgfmath@stack@operation=\toks24
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.
tex
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic
.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo
nometric.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando
m.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa
rison.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.
code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round
.code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.
code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ
erarithmetics.code.tex)))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex
\c@pgfmathroundto@lastzeros=\count95
))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co
de.tex
File: pgfcorepoints.code.tex 2013/10/07  (rcs-revision 1.27)
\pgf@picminx=\dimen116
\pgf@picmaxx=\dimen117
\pgf@picminy=\dimen118
\pgf@picmaxy=\dimen119
\pgf@pathminx=\dimen120
\pgf@pathmaxx=\dimen121
\pgf@pathminy=\dimen122
\pgf@pathmaxy=\dimen123
\pgf@xx=\dimen124
\pgf@xy=\dimen125
\pgf@yx=\dimen126
\pgf@yy=\dimen127
\pgf@zx=\dimen128
\pgf@zy=\dimen129
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst
ruct.code.tex
File: pgfcorepathconstruct.code.tex 2013/10/07  (rcs-revision 1.29)
\pgf@path@lastx=\dimen130
\pgf@path@lasty=\dimen131
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage
.code.tex
File: pgfcorepathusage.code.tex 2014/11/02  (rcs-revision 1.24)
\pgf@shorten@end@additional=\dimen132
\pgf@shorten@start@additional=\dimen133
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co
de.tex
File: pgfcorescopes.code.tex 2015/05/08  (rcs-revision 1.46)
\pgfpic=\box28
\pgf@hbox=\box29
\pgf@layerbox@main=\box30
\pgf@picture@serial@count=\count96
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst
ate.code.tex
File: pgfcoregraphicstate.code.tex 2014/11/02  (rcs-revision 1.12)
\pgflinewidth=\dimen134
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform
ations.code.tex
File: pgfcoretransformations.code.tex 2015/08/07  (rcs-revision 1.20)
\pgf@pt@x=\dimen135
\pgf@pt@y=\dimen136
\pgf@pt@temp=\dimen137
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod
e.tex
File: pgfcorequick.code.tex 2008/10/09  (rcs-revision 1.3)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c
ode.tex
File: pgfcoreobjects.code.tex 2006/10/11  (rcs-revision 1.2)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce
ssing.code.tex
File: pgfcorepathprocessing.code.tex 2013/09/09  (rcs-revision 1.9)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co
de.tex
File: pgfcorearrows.code.tex 2015/05/14  (rcs-revision 1.43)
\pgfarrowsep=\dimen138
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod
e.tex
File: pgfcoreshade.code.tex 2013/07/15  (rcs-revision 1.15)
\pgf@max=\dimen139
\pgf@sys@shading@range@num=\count97
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod
e.tex
File: pgfcoreimage.code.tex 2013/07/15  (rcs-revision 1.18)

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.
code.tex
File: pgfcoreexternal.code.tex 2014/07/09  (rcs-revision 1.21)
\pgfexternal@startupbox=\box31
))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co
de.tex
File: pgfcorelayers.code.tex 2013/07/18  (rcs-revision 1.7)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare
ncy.code.tex
File: pgfcoretransparency.code.tex 2013/09/30  (rcs-revision 1.5)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.
code.tex
File: pgfcorepatterns.code.tex 2013/11/07  (rcs-revision 1.5)
)))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod
e.tex
File: pgfmoduleshapes.code.tex 2014/03/21  (rcs-revision 1.35)
\pgfnodeparttextbox=\box32
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.
tex
File: pgfmoduleplot.code.tex 2015/08/03  (rcs-revision 1.13)
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-0-65.sty
Package: pgfcomp-version-0-65 2007/07/03 v3.0.1a (rcs-revision 1.7)
\pgf@nodesepstart=\dimen140
\pgf@nodesepend=\dimen141
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-1-18.sty
Package: pgfcomp-version-1-18 2007/07/23 v3.0.1a (rcs-revision 1.1)
))
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/utilities/pgffor.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex)
) (/usr/local/texlive/2018/texmf-dist/tex/latex/pgf/math/pgfmath.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex
Package: pgffor 2013/12/13 v3.0.1a (rcs-revision 1.25)

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex)
\pgffor@iter=\dimen142
\pgffor@skip=\dimen143
\pgffor@stack=\toks25
\pgffor@toks=\toks26
))
(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.cod
e.tex
Package: tikz 2015/08/07 v3.0.1a (rcs-revision 1.151)

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/libraries/pgflibraryplothan
dlers.code.tex
File: pgflibraryplothandlers.code.tex 2013/08/31 v3.0.1a (rcs-revision 1.20)
\pgf@plot@mark@count=\count98
\pgfplotmarksize=\dimen144
)
\tikz@lastx=\dimen145
\tikz@lasty=\dimen146
\tikz@lastxsaved=\dimen147
\tikz@lastysaved=\dimen148
\tikzleveldistance=\dimen149
\tikzsiblingdistance=\dimen150
\tikz@figbox=\box33
\tikz@figbox@bg=\box34
\tikz@tempbox=\box35
\tikz@tempbox@bg=\box36
\tikztreelevel=\count99
\tikznumberofchildren=\count100
\tikznumberofcurrentchild=\count101
\tikz@fig@count=\count102

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/modules/pgfmodulematrix.cod
e.tex
File: pgfmodulematrix.code.tex 2013/09/17  (rcs-revision 1.8)
\pgfmatrixcurrentrow=\count103
\pgfmatrixcurrentcolumn=\count104
\pgf@matrix@numberofcolumns=\count105
)
\tikz@expandcount=\count106

(/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/frontendlayer/tikz/librarie
s/tikzlibrarytopaths.code.tex
File: tikzlibrarytopaths.code.tex 2008/06/17 v3.0.1a (rcs-revision 1.2)
))) (./csnameuserissue.aux)
\openout1 = `csnameuserissue.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.

ABD: EveryShipout initializing macros
(/usr/local/texlive/2018/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count107
\scratchdimen=\dimen151
\scratchbox=\box37
\nofMPsegments=\count108
\nofMParguments=\count109
\everyMPshowfont=\toks27
\MPscratchCnt=\count110
\MPscratchDim=\dimen152
\MPnumerator=\count111
\makeMPintoPDFobject=\count112
\everyMPtoPDFconversion=\toks28
) (/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
Package: epstopdf-base 2016/05/15 v2.6 Base part for package epstopdf

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/grfext.sty
Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty
Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
)))
(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
)))
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO
)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2018/09/07 v3.3 Provides the ifpdf switch
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
38.
Package grfext Info: Graphics extension search list:
(grfext)             [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 456.

(/usr/local/texlive/2018/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.18 ..., 3.0) node[font=\commandfromfontcommand]{
                                                  Test 6};
? R
OK, entering \nonstopmode...
! Extra \endcsname.
\commandfromfontcommand ...sname \tiny \endcsname 

l.18 ..., 3.0) node[font=\commandfromfontcommand]{
                                                  Test 6};
I'm ignoring this, since I wasn't doing a \csname.

! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.19 ..., 3.5) node[font=\csname \tiny\endcsname]{
                                                  Test 7};
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Extra \endcsname.
\tikz@textfont ->\csname \tiny \endcsname 

l.19 ..., 3.5) node[font=\csname \tiny\endcsname]{
                                                  Test 7};
I'm ignoring this, since I wasn't doing a \csname.

[1

{/usr/local/texlive/2018/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./csnameuserissue.aux)

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
    tikz.sty    2015/08/07 v3.0.1a (rcs-revision 1.151)
     pgf.sty    2015/08/07 v3.0.1a (rcs-revision 1.15)
  pgfrcs.sty    2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
  pdftex.def    2018/01/08 v1.0l Graphics/color driver for pdftex
  pgfsys.sty    2014/07/09 v3.0.1a (rcs-revision 1.48)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.1a (rcs-revision 1.1)
  pgffor.sty    2013/12/13 v3.0.1a (rcs-revision 1.25)
 pgfkeys.sty    
 pgfkeys.code.tex
 pgfmath.sty    
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
epstopdf-base.sty    2016/05/15 v2.6 Base part for package epstopdf
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
  grfext.sty    2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
pdftexcmds.sty    2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
   ifpdf.sty    2018/09/07 v3.3 Provides the ifpdf switch
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 ***********

 ) 
Here is how much of TeX's memory you used:
 11292 strings out of 494585
 232447 string characters out of 6177395
 261399 words of memory out of 5000000
 14743 multiletter control sequences out of 15000+600000
 3640 words of font info for 14 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 55i,6n,54p,396b,487s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
</usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmr5.pfb>
Output written on csnameuserissue.pdf (1 page, 20122 bytes).
PDF statistics:
 19 PDF objects out of 1000 (max. 8388607)
 13 compressed objects within 1 object stream
 0 named destinations out of 1000 (max. 500000)
 13 words of extra memory for PDF output out of 10000 (max. 10000000)

问题更新

我尝试执行以下操作来检测输入是否是已定义的命令。但我仍然收到错误! Missing \endcsname inserted.

\documentclass{article}
\begin{document}

\newcommand{\command}{\Large}

\newcommand{\parseinput}[1]
{
\ifcsname #1\endcsname
\renewcommand{\command}{\csname #1\endcsname}
\else
\renewcommand{\command}{#1}
\fi
}

Test 0

\command
Test 1

\parseinput{\tiny}

Test 2

\command
Test 3

\parseinput{Large}

\command
Test 4

\parseinput{tiny}

Test 5

\command
Test 6

\end{document}

答案1

你不能像\tiny\csname这样放置字体命令

\documentclass{article}
\begin{document}

\newcommand{\command}{\Large}

\newcommand{\parseinput}[1]
{%%
\ifcsname \string#1\endcsname
\renewcommand{\command}{\csname \string#1\endcsname}%%
\else
\renewcommand{\command}{#1}%%
\fi
}

Test 0

\command
Test 1

\parseinput{\tiny}

Test 2

\command
Test 3

\parseinput{Large}

\command
Test 4

\parseinput{tiny}

Test 5

\command
Test 6

\end{document}

答案2

这是一个可替换的可扩展宏,用于检查第一个参数是否定义为控制序列。如果已定义,则\ifcsdefined{\test}{<true>}{<false>}扩展为,否则扩展为。类似地,检查是否已定义。<true>\test<false>\ifcsdefined{test}{<true>}{<false>}\test

\documentclass{article}

\makeatletter
\newcommand\ifcsdefined[1]{%
    \if\noexpand#1\relax
        \ifdefined#1%
            \expandafter\expandafter\expandafter\@firstoftwo
        \else
            \expandafter\expandafter\expandafter\@secondoftwo
        \fi
    \else
        \ifcsname#1\endcsname
            \expandafter\expandafter\expandafter\@firstoftwo
        \else
            \expandafter\expandafter\expandafter\@secondoftwo
        \fi
    \fi
}
\makeatother

\begin{document}
\verb|\tiny|: \ifcsdefined{\tiny}{yes}{no}

\verb|\teeny|: \ifcsdefined{\teeny}{yes}{no}

\verb|tiny|: \ifcsdefined{tiny}{yes}{no}

\verb|teeny|: \ifcsdefined{teeny}{yes}{no}
\end{document}

在此处输入图片描述

相关内容