New answers tagged

2

I think this is what you want: \documentclass{article} \usepackage{xparse} \usepackage{hyperref} \DeclareExpandableDocumentCommand{\foo}{smm}{% \texorpdfstring {\IfBooleanTF{#1}{\textsf}{\textit}{#2}--#3} {#2-#3}% } \begin{document} \section{This is \foo{A}{B}} \section{This is \foo*{A}{B}} \end{document}


0

All you needed was \string. \documentclass{article} \usepackage[english]{babel} \usepackage{xr-hyper} \usepackage[destlabel=true]{hyperref} \makeatletter \newcommand{\foo@star}[2]{\textsf{#1}-{#2}} \newcommand{\foo@plain}[2]{\textit{#1}-{#2}} \DeclareRobustCommand{\foo}{\@ifstar\foo@star\foo@plain} \makeatother \newcommand{\mysection}[1]{\section[\string ...


2

I admit I don't fully understand what you're trying to do here, but as egreg notes, \begin and \item are fragile which is what's causing the problem. It's easy enough to "fix" this particular example \newcommand{\wrapper}[1]{% \test{% \begingroup \let\begin\relax \let\item\relax \let\end\relax \protected@edef\x{% ...


1

The best alternative is of course expl3: \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\NewPoints}{m} { \clist_map_inline:nn { #1 } { \cs_set:cpx { ##1 } { a-\NumNode-\theLittNode } \stepcounter{LittNode} } } \ExplSyntaxOff


2

Your errore was that the column type for tabularx is X, not x. I simplified you code, loading xcolor with option table (which loads colortbl in that case) and using the \rowcolors command. Also, I loaded the boldline package, to have variable thickness rules, and gave some vertical padding with \arraystretch: \documentclass{article} ...


0

Based on http://tex.stackexchange.com/a/5020/36296 you could do somthing like \documentclass{article} \usepackage{xcolor} \usepackage{tabularx} \usepackage{colortbl} \usepackage{array} \newcolumntype{x}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}} \begin{document} \begin{tabularx}{\textwidth}{x{.465\textwidth}x{.465\textwidth}} ...


1

Full customizable and human readable node names with no interaction between different macros. \documentclass{article} \usepackage{tikz} \usetikzlibrary{quotes} \makeatletter \newcommand{\NewPoints}[1]{% \expandafter\edef\csname #1\endcsname{% a-\NumNode-\theLittNode} \stepcounter{LittNode} %} } \makeatother % counter for naming nodes ...


3

The important thing in the application you seem to have in mind is not forcing a too rigid setting. Thus I store each authors' list as itself, but as the argument to another command, which can be set at usage time in a variety of ways. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\addauthors}{m} { \mapo_addauthors:n { ...


6

If I see given "user environment" (last twelve lines in your code) and desired output, then I can say: it is very simple to do it at TeX primitive level: \def\alist{}\def\plist{} \def\Aa#1{\edef\alist{\alist,\detokenize{#1}}} \def\Af{\edef\plist{\ifx\plist\empty\else\plist, \fi (\ifx\alist\empty\else\expandafter\applyand\alist,,\fi)}% ...


2

Because some times we like to reinvent the wheel. Here is a an approach that allows you to alter the format on the fly among other things. \documentclass{article} \usepackage{etoolbox} \usepackage[T1]{fontenc} \usepackage{lmodern} \makeatletter %% ----------------------- %% %% --- Defining a list --- %% ...


4

I now see from your other questions that, despite your comments concerning how easy it is to do this in modern programming languages, you are determined to compare those languages with TeX, rejecting the modern interfaces which build upon it. Little wonder, then, that the TeX case seems more difficult. For a fair comparison, you need to compare other ...


5

Werner's analysis is very good. Here's an alternative implementation with xparse and expl3. Note that you can define as optional argument to \print the separator between items (default is “comma-space”). \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\aAdd}{m} { \mapo_aadd:n { #1 } } \NewDocumentCommand{\bexp}{} { ...


9

\expandafter doesn't expand everything after it, just the following token. Also, since it seems like b@counter measures the content added to \b@toks, I don't see the need for \ifnum... \else\b@toks=\expandafter{\the\b@toks (\the\a@toks) } \fi where you want to add (an empty) \b@toks to itself. The following produces what you're after, I think (I've ...


4

Define \UnitLabel with an argument: \documentclass{article} \usepackage{lipsum} \usepackage{xparse} \newcounter{Unit} \NewDocumentCommand{\UnitLabel}{m}{% \makebox[4.5em][l]{Unit #1}% } \NewDocumentCommand{\Unit}{ m }{% \refstepcounter{Unit}% \section*{\UnitLabel{\Roman{Unit}}#1} \addcontentsline{toc}{section}{\UnitLabel{\Roman{Unit}}#1}% } ...


3

Use \DeclareExpandableDocumentCommand -- this does not allow an optional argument at the end of the argument list, but this is no issue here! The \NewDocumentCommand version isn't expandable, see e.g. \show\UnitLabel: \UnitLabel=\protected macro: ->\makebox [4.5em][l]{Unit \Roman {Unit}}. l.25 \show\UnitLabel i.e. \UnitLabel is protected. The xparse ...


1

Another approach is to create a stack that contains the nodes for a macros. Each call to a macro create en new level in the stack, and the level is deleted at the end of the macro. One can preserve the nodes one chooses by picking them, and only ones that are useful for the future. One declares some nodes (human readable names) at the beginning of the ...


1

\apptocmd doesn't like to be in the argument to another command when # is involved. You can do it with a conditional: \documentclass{article} \usepackage{etoolbox} \newcommand\app[1]{\textbf{#1}} \newif\ifdebugmode \debugmodetrue % comment for not applying the patches \ifdebugmode \newwrite\appfile ...


2

I am unclear on the detailed behavior desired, but... Is this what is desired? \documentclass{article} \usepackage{xpatch} \newcommand\app[1]{\textbf{#1}} % <- #1 is appended's macro's parameter \def\addtoapp#1{% \apptocmd{\app}{#1}{}{} % <- passing appended macro's parameter to appended macro again } \begin{document} \app{Food App} \addtoapp{This ...


7

If I understand correctly, you want to use the relative positions of the saved nodes in your new picture. That is, each node should refer to a position in the new picture relative to the new origin. Here's some code that saves all the data for a list of specified nodes which can then be restored at a later time in the document. It uses LaTeX3 stuff ...



Top 50 recent answers are included