# Tag Info

## Hot answers tagged macros

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 ...

6

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 ...

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)}% ...

5

What you need to know for doing a "box arithmetic" is TeX changes vertical to horizontal mode at some places and returns back at others places. \vbox or \vtop has its width given as most wider element in it. If this is whole paragraph then the width is \hsize. So it is typical to set a width of \vbox or \vtop by \vtop{\hsize= something ...} When TeX is ...

5

The OP's first example is \documentclass{article} \newcommand{\new}{} \begin{document} \new{Why is this printed?} \end{document} and he/she wonders why "Why is this printed?" get printed out. The key to understand here is that something following a macro name, even if it looks like an argument, such as \new{Why is this printed?}, is only an actual ...

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}{} { ...

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 ...

4

The main part of the code you quote is \setbox\z@\hbox{\csname Ginclude@#1\endcsname{#3}}% which calls \Ginclude@xxx where xxx is the file type (determined from the extension or passed as an key to \includegraphics) so if xxx is eps this will call \Ginclude@eps and if the driver specified (in an option or set in graphics.cfg) is dvips then dvips.def will ...

4

Here's an implementation with a patched and redefined \includegraphics. Currently, the width of the filename is not accounted for, but one can do that by changing the T argument to F in the \stackengine argument list. The underset gap of the filename is currently 3pt. Note that the filename is generated properly, regardless of whether the extension was ...

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

Here is a completely different approach using pgfkeys. With all of the comments the code is longer than Manuel's so pehaps I can't claim simplicity, but I just like using pgfkeys for things like this. To show that it works here's what my code produces: ...and here is the code: \documentclass{article} \usepackage{etoolbox} \usepackage{pgfkeys} ...

3

Your code is equivalent to \documentclass{article} \begin{document} \mbox{\section{abc}} \end{document} \raisebox makes a horizontal (LR) box like \mbox so vertical display constructs like \section are not allowed. unrelated to the error but if you took \section out of the box: \raisebox{-1mm}{ \textcolor{color1}{ ...

3

Change your code into \clist_new:N \g_mapo_allauthors_clist \NewDocumentCommand\addauthor{m} { \clist_gput_right:Nn \g_mapo_allauthors_clist { #1 } } \NewDocumentCommand \printall { } { } % initialization \DeclareExpandableDocumentCommand \printall { } { \clist_use:Nnnn \l_mapo_allauthors_clist { ~and~ } { ,~ } { ~and~ } } The main point is ...

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 { ...

3

Of course you get an error: if you want to use scrartcl you have to call \usepackage[nochapters]{classicthesis} However your redefinition of \spacedlowsmallcaps makes no sense: \renewcommand{\spacedlowsmallcaps}[1]{\SC{#1}} is probably what you want. There is no need to do tricks, though. \documentclass[10pt,letterpaper]{scrartcl} ...

3

A 'traditional' way with the \@elt splitting feature: Counter reset lists use the \@elt splitting, i.e. the counters that should be reset by foo counter are stored this way: foobar\@elt otherfoobar\@elt. The list is named cl@foo and is called each time in stepping command, whereas \@elt is a 'volatile' macro, being defined to do some action. The same ...

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 ...

3

Like this? \documentclass{article} \usepackage{xcolor} \newcommand{\sectioncolored}[3]{% \section{\textcolor{#1}{#2} #3}% } \makeatletter \def\entrylistsplitfirst#1 #2\@nil{#1} \def\entrylistsplitsecond#1 #2\@nil{#2} \newenvironment{entrylist}[2]{% \edef\tempa{\expandafter\expandafter\expandafter\entrylistsplitfirst #2\@nil}% ...

2

Add it to the node options, so that it affects the whole node, and not just a part of it: font=\Large Also, the shape is a rectangle by default, and draw uses black by default. So in the end you can just write: \newcommand{\orgnode}[2]{\node[draw, font=\Large, align=center] at (#2) {#1};}

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 ...

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 --- %% ...

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 ...

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

Are you really sure you wish to check for control sequence tokens? Primitives like \relax are not macros but they are control sequences. Active characters (character tokens of category code 13) are not control sequence tokens but they can be defined to be macros. A control sequence token or an active character token whose meaning denotes that it is ...

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

1

May be you need something like this: \long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} \def\traceparam#1{\def\paramL{}\traceparamA #1\end} \def\traceparamA{\futurelet\next\traceparamB} \def\traceparamB{% \let\nexts=\undefined \expandafter\ifx\space\next \let\nexts=\traceparamS \fi \ifx\bgroup\next \let\nexts=\traceparamD \fi ...

1

I think this works, but haven't tested thoroughly \documentclass{scrartcl} \usepackage{hyperref} \newcounter{req} \newcommand*\getid[1]{\def\thereq{#1.\arabic{req}}\refstepcounter{req}\thereq} \begin{document} \begin{itemize} \item \getid{ITEM} \label{itemkeyone} \item \getid{ITEM} \label{itemkeytwo} \end{itemize} \ref{itemkeyone} \end{document}

1

You can use standard \parbox and \makebox commands. There is a subtle point that you seem to be overlooking: the baselineskip might be not uniform with a \vtop (or \parbox[t], which is the same) approach. \documentclass[fontsize=13pt,letterpaper]{scrartcl} \usepackage[textwidth=5in,showframe]{geometry} \usepackage{fontspec} ...

1

The \printall must be expanded first, i.e. use pdfauthor=\expandafter{\printall} \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \clist_new:N \l_allauthors_clist \NewDocumentCommand\addauthor{m}{% \clist_put_right:Nn\l_allauthors_clist{#1}% } \NewDocumentCommand \printall{}{ ...

1

The glossaries package has been changed since this question and the other answer were posted. If you are still encountering this problem, update your version of glossaries. Note that \newglossaryentry is still a “short” command, so you can't have paragraph breaks (except through \glspar). \longnewglossaryentry allows explicit paragraph breaks. It's best to ...

Only top voted, non community-wiki answers of a minimum length are eligible