# Tag Info

## New answers tagged macros

1

Use \MakeUppercase: \documentclass{article} \usepackage{tikz} \definecolor{spotcolor}{cmyk}{.40,0,.70,0} \newcommand\level{starter} \begin{document} \begin{tikzpicture} \node [ white, fill=spotcolor, rounded corners=4pt, inner sep=4pt, font=\sffamily] at (-1.1in,-.7in){\tiny\MakeUppercase { \level }}; \end{tikzpicture} \end{document}

0

uhmm... I'm going to state some experiment result. It seems that the problem is not due to the new command definition. When I change the \subheadfont to be defined by some other fonts, for example, Times New Roman and write some English words as subhead(i.e. \subhead{This is subhead}) the English characters could be typeset italic. Moreover, when I adopt ...

4

This is very similar to what Leslie Lamport recommends in his LaTeX: A Document Preparation System, except he advises that you enclose the entire [ ... ] in braces. It really comes to very much the same thing, by having {[ ... ]}, you are telling LaTeX that [ ... ] is to be taken separately. I suppose with {} you are almost providing insulation, if you see ...

5

Improved code with 'grouping' of persons and hyperlinks (if needed) \documentclass{book} \usepackage{marginnote} \usepackage{xparse} \usepackage{totcount} \usepackage{morewrites} \newcounter{dummycounter} \newcounter{personposition} \newtotcounter{personcounter} \makeatletter \def\latex@starttoc#1{% \begingroup \makeatletter \@input{\jobname.#1}% ...

3

You can use the powerful apnum macros. \documentclass{article} \input apnum \def\binom#1#2{{\evaldef\n {#1} \evaldef\k {#2}% \evaldef\X {\FAC{\n}/(\FAC{\k}*\FAC{\n-\k})}\X}} \begin{document} \binom{2^4-3}{2^3} \end{document} Note that apnum can also be used in plain TeX, because it does use only TeX primitives. (And also note the joke message ...

4

xint should have a binomial function but I forgot to include it in the last release. Here is one way in the meantime: The update has permuted the order of presentation, as testing proved that the simpler approach using the built-in factorial was significantly faster except for cases with a small #2. \documentclass{article} \usepackage{xintexpr}% at least ...

7

A delimiter is needed to convince the environment macro (or any other macro) that the argument list is finished and all other stuff is not to be processed by the macro itself. This delimiter is a {}, empty space is ignored. See the examples where foobar uses [...] as normal text, whereas foobaropt expects an optional argument and interpretes it that way ...

2

Glyphs can be larger than their bounding box: \documentclass{article} \begin{document} \fboxsep0pt \fbox{$\widetilde{\mathbf{l}}$} \end{document} You can enlarge the border of preview by changing the length \PreviewBorder

1

You could use bigintcalc: \documentclass{article} \usepackage{bigintcalc} \newcommand{\bigintcalcBinomial}[2]{% \bigintcalcDiv {\bigintcalcFac{#1}} {% \bigintcalcMul {\bigintcalcFac{#2}} {\bigintcalcFac{\bigintcalcSub{#1}{#2}}}% }% } \begin{document} ...

2

You need to change \def\ba#1{\begin{array}#1} to \def\ba#1{\begin{array}{#1}} Observe the pair of curly braces around #1 in the second line of code. Incidentally, you shouldn't use  directly in a LaTeX document to initiate and terminate displaymath mode; use $and$ instead. For more information on this subject, see the postings Why is [ ... ] ...

2

You could use forest to draw the trees. Since it requires a specification of a tree in brackets notation, it seems at least potentially suitable. Unlike the existing solutions, this one does not require LuaTeX. The examples below were compiled using pdfTeX, but any engine should work. I present 2 versions: The Original Edition requires you to write [] ...

3

A variant of Symbol1's answer that doesn't require auxiliary files. However, for technical reasons, instead of a period a * is used. \documentclass{article} \usepackage{tikz} \usetikzlibrary{graphs,graphdrawing} \usegdlibrary{layered} \newcommand{\setupbseriesactive}{% \begingroup\lccode~=[ \lowercase{\endgroup\def~{/--\iftrue{\else}\fi}}% ...

4

The basic idea is to use TikZ's graph-drawing mechanism. It accepts something like \graph{/--{/--{/,/},/}}; to draw a graph. So the next step is to translate [ is /--{ ] is } , is , . is / This is quite hard since TikZ does not like \graph\bgroup/--\bgroup/--\bgroup/,/\egroup,/\egroup\egroup; (Internally every pair of { and } will become an ...

1

If you want to make a macro equivalent to another one, use \let (with \global if you want so): \documentclass{article} \begin{document} \def\coucou{\begin{itemize} \item aa \item bb \end{itemize}} \coucou \def\aa{zz} \expandafter\let\csname persocmd\aa\endcsname\coucou \persocmdzz \end{document} If you want a global definition, just add ...

2

I think that bm can be helpful: \documentclass{article} \usepackage{amsmath} \usepackage{bm} \newcommand{\tn}[1]{\bm{\mathsf{#1}}} \begin{document} Good sizes (and $\mathsf{A}$ for comparison) $h=\tn{A}+\tn{B}^2 + \hat{\tn{C}}$ But the sizes are bad when superscripts or subscripts are involved ...

1

For automatic sizing of material in subscript and superscript positions, don't use the basic \mbox command. (Here, "basic" means "defined in the LaTeX kernel.) Instead, be sure to load the amsmath package and use the \text command. The setup of the \tn macro should thus be as follows: \newcommand{\tn}[1]{\text{\boldmath$\mathsf{#1}$}} Because \tn only ...

4

inside \parbox, tabular p columns, minipage etc, various commands are normalised to a known state, specifically they all run \@arrayparboxrestore which by default is \def\@arrayparboxrestore{% \let\if@nobreak\iffalse \let\if@noskipsec\iffalse \let\par\@@par \let\-\@dischyph \let\'\@acci\let\\@accii\let\=\@acciii \parindent\z@ \parskip\z@skip ...

3

This generates the counter on the fly although this is not recommended in any case. If the counter name given as first argument already exists, there is a command \c@#1 already which is LaTeX representation of a counter (well, top layer on \count.... registers actually. If \@undefined{c@#1} is true, define the new counter and set it to one, displaying ...

12

Yes, of course. \documentclass{article} \begingroup \catcode+=\active \gdef+{\mathbin{\mathrm{blurb}}} \endgroup \AtBeginDocument{\mathcode`+="8000 } \begin{document} $x+y$ \end{document} Of course you can think to better definition for the “math active” +. ;-)

0

For my setup, putting the macros in the TeX tree is not a good option because I synchronize my user directory among different machines. What I do with macros and bibliography is to put them at the top of my working tree. Then in a new document I use something like \input ../../macros.tex .

2

Create you own package, and put them in your texmf tree. A package is just a macro file with these characteristic: .sty extension no need of \makeatletter…\makeatother a \ProvidesPackages command. using \RequirePackage instead of \usepackage. You should indeed versionning it, for example with git. Cf my own macro file ...

3


3

Use \newcommand{\Prof}{Prof.\@} as a possible macro for replacing the text easily with a single change. Be careful about using \Prof in conjunction with text later on (which is very likely), since whitespace is gobbled and the text is glued to the expansion of \Prof. If you don't mind be struck down by the thunderbolts by egreg use xspace ;-) ...

1

As mentioned in the comments to the question, defining a new command as \\\\ is impossible, because redefining \ conflicts with the existing meaning of \ used as an escape sequence. Even if \\\\ seems to be more convenient to type instead of \\[\normalbaselineskip], this is not a good coding practise (loss of readability). Use cases like adding more ...

3

Let's see what happens with the call \long\def\linesaver#1{\obeylines#1} \linesaver{ Test1 Test2 } Since \linesaver has one argument, TeX absorbs it and performs tokenization; so the end-of-lines get changed into space tokens before \obeylines enters into action. It does when the argument has already been absorbed, so there's no ^^M in the argument and, ...

6

this has lots less finesse than egreg's suggestion, but sometimes brute force works. \let\oldpar\par \def\ignorepar{\let\par\ignorespaces} \def\restorepar{\endgraf\let\par\oldpar} \def\bye{\endgraf\end} \ignorepar abcdef ghijkl mnopqr stuv wxyz abcdef ghijkl mnopqr stuv wxyz abcdef ghijkl mnopqr stuv wxyz abcdef ghijkl mnopqr stuv wxyz \restorepar ...

4

Spaces need special treatment to be ignored as they are character tokens but \par is a csname so you can more simply do \let\par\empty (which latex does for example in tabular) (obviously you need some hook such as end of group to restore the definition if \par is ignored in this manner.)

7

Let's do it slowly: \ignorepars\par x becomes \futurelet\next\ignoreparsA\par x Now \next is \let to \par and \ignoreparsA is expanded, so we have \ifx\next\par\expandafter\ignorepars\eat\fi\par x The conditional is true, so \ifx\next\par disappear, leaving \expandafter\ignorepars\eat\fi\par x Now \expandafter expands \eat, which has empty ...

1

The currfile package provides several methods to get the name and the path of the current file. For instance, you can use the \currfilename macro: \ClassError{myclass}{Entry requires version selection using \protect\selectversion \on@line (\currfilename)}{} Note that it might not work in some cases. For instance, if you load the currfile package in a ...

1

You might do like the following: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{mfirstuc} \usepackage{titlesec} \titleformat{\section} {\normalfont\scshape} {\thesection} {1em} {\makefirstuc} \begin{document} \section{Capital} \section{capital} %\section{équipe} \end{document} but, as soon as the third \section command is ...

1

If you really want the last be optional then use the TeX level for the new command: \documentclass{article} \makeatletter \def\mysec#1#2{\@ifnextchar[{\mysec@i{#1}{#2}}{\mysec@i{#1}{#2}[]}}% \def\mysec@i#1#2[#3]{% \textbf{#1} \\ #2 \ifx\relax#3\relax \else \\ #3 \fi}% or whatever you want to do with #3 \makeatother \begin{document} \mysec{foo}{bar} ...

2

I suggest to use xparse and \RenewDocumentCommand with provides easier ways to define macros with optional arguments The argument specification somo says to use a starred (#1), optional (#2), mandatory (#3) and a final optional argument (#4), if needed. Redefining the sectioning commands should be done with care since they provide a starred variant which ...

3


5


13

You probably compiled the following minimal example: \documentclass{article} \begin{document} Hello World! \end{document} which provided the following (partial) .log: ... \c@part=\count79 \c@section=\count80 \c@subsection=\count81 \c@subsubsection=\count82 \c@paragraph=\count83 \c@subparagraph=\count84 \c@figure=\count85 \c@table=\count86 ... The above ...

21

The tcolorbox package can nicely display literal LaTeX code and its output when being called in a very configurable manner, depending on the argument of the tcblisting environment. This environment displays by default LaTeX code literally but the coding/scripting etc. language can be changed to anything known to the underlying listings package too. (or ...

4

The problem appears to be an expansion issue in the interaction of pgfplots and \includegraphics. It can be reduced to the following minimal working example: \documentclass{standalone} \usepackage{graphics} \newenvironment{type}[1]{% \newcommand\getFile[1]{% directory1/#1/##1} }{} \begin{document} \begin{type}{directory2} File: ...

0

Thanks to Jérôme's comment, I was able to find a solution: use \newcolumntype instead of \newcommand: \documentclass[letterpaper,20pt]{extarticle} \usepackage[table,xcdraw]{xcolor} \newcolumntype{R}{>{\columncolor{red}}l} \begin{document} \begin{tabular}{l >{\columncolor{red}}l} A & B \\ \end{tabular} \begin{tabular}{l R} A & B \\ ...

2

You're forgetting \ignorespaces: with \noindent you start a paragraph, so spaces are not ignored, unless you tell TeX to. \outer\def\section#1{% \medbreak \noindent{\bf#1}\par \nobreak\smallskip \noindent\ignorespaces } Note that \nobreak should go before \smallskip because TeX is allowed to break at glue, if not preceded by discardable items ...

3

Using \noindent means that your heading command has already started the first paragraph. If you know that sections always start with text this is OK (and in the spirit of plain tex commands that aim to be simple and easily customised rather than generally robust). The disadvantage is if you want to start any section with any vertical display material such ...

1

Try \newcommand{\dualminipage}[2] { \begin{minipage}[t]{0.45\linewidth}#1\end{minipage} \hfill \begin{minipage}[t]{0.45\linewidth}#2\end{minipage} } It seems that second square backed in your\dualminipage definition make a problem.

1

This implementation allows that any text following the \marks argument gets pushed onto a new line, rather than get tacked onto the same line as the \marks argument. \documentclass{article} \renewcommand\marks[1]{\ \hfil\allowbreak\mbox{}\hfil\mbox{\bfseries #1}\break} \begin{document} Here is the first text. \marks{Here is the second text.} And here is ...

2

The following code will solve your problem: \renewcommand{\marks}[1]{% \unskip\nobreak\hfil\penalty50\null\nobreak \hfil\textbf{[#1\hphantom{a}marks]}% \parfillskip 0pt\finalhyphendemerits0}

1

One way to do this would be to patch \compound: the etoolbox package contains commands that allow one to prepend or append code to an already defined command. See this post for a good explanation of this. In order to get a comma-separated list, we'll patch the command to write its argument to a file whenever it is called: \usepackage{etoolbox} ...

7


2

enumitem expects a key-value sequence and therefore doesn't expand the optional argument that is supplied. If you're sold on using this interface, you need to make sure that enumitem receives an expanded version of what you supply. Below I've redefined enumerate to expands its optional argument. I've also opted to use a different way of printing \APLbox ...

4

Here is a modification of my answer to a previous question asking to add margin notes the first time a reference is made. This uses the cleveref package to allow context-aware citations, which makes underlining the name as well as number easy. Edit: As pointed out by @egreg below, the previous answer would break if a list of references was passed to \cref. ...

2

You have to expand both macros passed to \ifstrequal, but the string of \expandafters you're using only affects the first (and not really, I'd say). The standard technique, if the data is ASCII strings, is to use \edef: \begin{filecontents*}{\jobname.csv} "TRANSID","DATE","QUANTITY" "141f8b4a-e83e-4222-911a-5a977b4d0afca","11/9/2015","10" ...

6

I see no problem with using the \thanks macro for this purpose. \documentclass{article} \begin{document} \author{J. Doe, Q. Public, J. Schmo\thanks{Corresponding author.}} \title{A nice paper} \maketitle \end{document} If you prefer to set up a dedicated macro named \correspondingauthor, you could proceed as follows: \documentclass{article} ...

4

Perhaps something like this, which just uses a \footnote and the symbol option of the footmisc package. \documentclass{article} \usepackage[symbol]{footmisc} \begin{document} For example, you might have the following authors: J. Doe, Q. Public, J. Schmo\footnote{Corresponding author.} and at the bottom of the first page, there would be a footnote: ...

Top 50 recent answers are included