# Tag Info

6

The expansion of \ref... leads to the error. However, the xstring knows the \noexpandarg macro, preventing the the expansion of the argument of the main input string to xstring macros, but after the first operation expansion must be enabled again, using \expandarg. \documentclass[12pt]{book} \usepackage{xstring,lettrine} ...

6

\documentclass{article} \usepackage{url} \usepackage{pgffor} \usepackage{xparse} \usepackage{xstring} \usepackage[colorlinks=true]{hyperref} \NewDocumentCommand{\FormatLinks}{% s% #1 =* not used yet O{}% #2 = optional title m% #3 = Mandatory title m% #4 = URL Link }{% \par \hspace*{1.0cm}\href{#4}{#3\IfValueT{#2}{~#2}}% }% ...

6

You could add the line \xdef\resa{\resa}%% to your code. But things still won't compile properly because your multiplier gets you out of the range from 0 to 1. \documentclass{article} \usepackage{fp,xcolor,colortbl} \FPeval{\resb}{0.5} \newcommand{\he}[1]{% \FPeval{\resa}{2 * #1}% \xdef\resa{\resa}%% \cellcolor[gray]{\resa}% #1 } ...

6

The following example solves the issue by expanding \resa before \cellcolor is expanded and looks at its arguments. The second problem is, the range for the color model gray is between 0 and 1 inclusively. The values 0.8 and 1.0 exceed this, when multiplied by 2. Therefore the example checks the result and limits it to 1 if necessary. ...

6

The macro \macro (sic!) is defined to have an optional argument. If this missing, the call \macro{3}{4} is the same as \macro[]{3} and the figure 4 will be read for the next tabular row. The column shift in the 'wrong' usage is clearly visible. 3 is in the 4th column, instead of the requested 3rd column. \documentclass[a4paper,10pt]{article} ...

5

The box is quite deliberately never used. The idea here that that \beamer@@@temp might contain material that gets typeset. Carried out inside a box, anything that does end up typesetting material causes no problem inside the document as the box is thrown away. All that is needed after this code is the results of the decoding, which are set globally so are ...

5

A simpler solution using expl3 and its powerful fp module. \documentclass{article} \usepackage[table]{xcolor} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\he}{m} { \cellcolor[gray]{ \fp_eval:n { min ( 2*#1, 1 ) } } #1 } \NewDocumentCommand{\hetest}{m} { \cellcolor[gray]{ \fp_eval:n { min ( 2*#1, 1 ) } } \textcolor{red}{#1 ~ -- ~ ...

5

You can do some catcode magic. The general idea is as follows \documentclass{article} \makeatletter \newcommand\detokenizeWithComments{%% \bgroup \catcode\%=12 \ae@detokenize@with@comments } \def\ae@detokenize@with@comments#1{%% \detokenize{#1}%% \egroup} \makeatother \begin{document} Hello world \detokenizeWithComments{This ...

5

You can also do it with latex or pdflatex, by using the packages fontenc (encoding for the printed text) and inputenc (encoding for the source file). \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \begin{document} àâéèêîôùû \end{document} You can see this question for more details.

5

I would use different commands, one to hold the name and another to set the name. In a package, it is a common practice to use an external version of the command (\name) to set the value of an internal macro (\@name). This is how \author and \title work in the article class. \makeatletter \newcommand{\name}[1]{\gdef\@name{#1}} \makeatother But it would ...

4

Don't. Just don't typeset é as \'e, if you need lots of them. Typeset them as é using your French keyboard, store the file as utf-8, and compile with a Unicode-aware TeX engine like xelatex. See, however, the comments below the answer of T. Verron: xelatex is not the standard engine. Therefore you might prefer a solution that works with pdflatex.

4

The example in the question reveals quite some show stoppers: Package graphics needs to know the file name extension and calls LaTeX's \filename@parse to split the path specification. \filename@parse expands the first token once. Thus it is possible to put the starting path in a macro. But after the expansion step, further macros or nested macros are not ...

4

Not sure I'd use xstring if you already have l3 and pgf loaded but anyway: \documentclass{article} \usepackage{url} \usepackage{pgffor} \usepackage{xparse} \usepackage{xstring} \usepackage[colorlinks=true]{hyperref} \NewDocumentCommand{\FormatLinks}{% s% #1 =* not used yet O{}% #2 = optional title m% #3 = Mandatory title m% #4 = URL ...

4

A number of commands in unicode-math are contained in \AtBeginDocument so are first run around the point when the processing gets to the \begin{document} command. You can use the same trick yourself to override a definition: \documentclass[a4paper,11pt,twoside,fleqn]{report} \usepackage{mathtools} \usepackage[bold-style=ISO]{unicode-math} ...

4

It seems to me as overcomplicated. Why there are the \StrBefore etc. processing? Why do you need letrine package? You can do the same by this: \documentclass[12pt]{book} \usepackage[pagebackref]{hyperref} \hypersetup{ linktoc=all, colorlinks=true, allcolors=red }% \def\openintro#1{\openintroA #1 \end} \def\openintroA#1#2 #3 #4\end{\par ...

4

The traditional way, before xparse allowed for more flexible solutions, is to use \@ifnextchar[ to check for the [ of the optional argument and to inject other code into the wrapper. The starred version is included as well and can have an [] now as well -- it's up to the OP to decide what this [] should do then ;-) \documentclass{book} ...

4

Yes, there is a better way: \usepackage{xparse} \NewDocumentCommand{\mychapter}{som}{% %%% things to do before \chapter \IfBooleanTF{#1} {\chapter*{#3}} {\IfNoValueTF{#2}{\chapter{#3}}{\chapter[#2]{#3}}% %%% things to do after \chapter } This supports all three calls: \mychapter*{Title} \mychapter{Title} \mychapter[Short title]{Long title} ...

3


3

If you want the macro without the optional argument: \documentclass[a4paper,10pt]{article} \newcommand{\macro}[2]{% notice the lack of the second brackets here & something & #2 & #1 \\ } \begin{document} \begin{tabular}{lccc} \macro{3}{4} \end{tabular} \end{document}

3

xunicode sets up for these commands also some OT1 defaults, but the main point are accents commands. E.g. \DeclareEncodedCompositeCharacter{\UTFencname}{\M}{0322}{0322} % (Combining retroflex hook below) You can naturally redefine the command if you don't use it, but there is a tradition to use "one-char-commands" for accent commands and so I would never ...

3

Due to how you defined \lowsc, the redefinition in the header applies to nothing, because what TeX sees at that point is not \lowsc any more, but \scalebox{0.8}{i}. Using \DeclareRobustCommand for \lowsc solves the problem. I'd use a conditional, however. \documentclass{scrreprt} \usepackage[markcase=lower]{scrlayer-scrpage} \usepackage{graphics} ...

3

Your \listLength command doesn't work by pure expansion; you should say \newcommand*{\listLength}[1]{% \setcounter{listlength@cnt}{0}% \forcsvlist{\listlength@add}{#1}% } as the definition of \listLength and then \listLength{\@glo@types}% \addtocounter{mtc}{\value{listlength@cnt}}% in the code. There's a much slicker way with expl3: ...

3

Sure, why not. Your use, your choice. Depending on the specific application, you might consider using \xdef take make the (expanded) redefinition global or \protected@xdef to accommodate "strange constructions" in names...

2


2

I'm answering my own question, by using part of the code provided by @wipet and lettrine (since it is easier to manipulate the text styling). Instead of using the whole string manipulation of my first question, I just use the following code (which replaces the entire \newcommand{\openintro}): \def\openintro#1{\openintroA #1 \end} \def\openintroA#1#2 #3 ...

2

without evidence to the contrary, \hip appears to be a "fragile" command. adding \protect before a fragile command in a "moving argument" (the argument to a command like \paragraph that can potentially also be used somewhere else, such as in the toc) will avoid the problem. so here, \protect\hip. more information on this situation can be found with the ...

2

Font switches such as \itshape, \mdseries and \scshape tell LaTeX to switch to a different font. The font LaTeX switches to depends on the currently active family, and the various fonts corresponding to the different attributes (weight, shape etc.) are usually defined in a font definition file. Simplifying reality somewhat, when you say \itshape this is ...

1

Well, the error is quite clear: the code \begingroup\edef\x{\endgroup\noexpand\lstinputlisting[label=#4, name=#4] {#2} {\ME@decorations} % Decorating comments }\x should be \lstinputlisting[label=#4, name=#4] {#2} \ME@decorations % Decorating comments There's absolutely no reason for using the \edef\x trick here and the problem is exactly that ...

1

The solution depends on the alphabet, used for the variables. If these are identifiers with upper and lower case letters, digits, underscore and some other harmless symbols (with category code 12/other, as punctuation chars) then \detokenize can be used to normalize the category codes of the identifier to token with category code 12 (same as digits): ...

1

The following answer is based on http://tex.stackexchange.com/a/58512/36296 and the author definition in latex.ltx main.tex \documentclass{beamer} \usetheme[myText=Hello World!]{tudrobert} \author{George Orwell} \title{Animal Farm} \date{\today} \institute[TUD] \def\uni{Hello World!} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} ...

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