{macros} is for questions specifically concerning TeX's macro processor. Note that, because TeX uses macros ubiquitously, most questions about code that uses macros are not looking for information about how macros work, and so are not appropriate for this tag.

learn more… | top users | synonyms (4)

7
votes
2answers
105 views

newcommand: different behavior depending on number of args?

I want to make my citations simpler. I'm in theoretical physics where citations are numbered, so \cite{citation} will pull up simply "[1]" (for example). Common usage is to write "Ref. [1]." I made a ...
4
votes
2answers
70 views

Defining a macro with combine many options to one bracket

I am beginner in writing macros with multi options. What I want to do, is to combine many options to one pair of brackets. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} ...
16
votes
4answers
794 views

How to draw the following box using TikZ?

How to draw the following boxes using TikZ? EDIT (22.09.)
18
votes
4answers
457 views

Are \end… macro names reserved in LaTeX2e?

Perhaps this question has been asked before, but I could not track the correct question down. I stumbled accidentally over this feature: Say, I want to make a ...
7
votes
2answers
219 views

Lower case first character

How do you make a macro that takes 1 argument and forces the very first character to low? So you could write the following: \firstToLow{SOME TEXT INPUT OF VARIATING LENGTH} And then get this ...
9
votes
3answers
237 views

Is there a way to define a newcommand that can evaluate mathematical expressions

Let's suppose that I have a very complicated function that depends on i and j. So I define a new command, say \newcommand{\foo}[2]{X_{i+j+1}}. % This might be an complicated expression, but I want ...
0
votes
0answers
40 views

captionof{} and double-spacing

I am combining Tikz pictures with \includeimage in my thesis, which means I am mixing \captionof{} and \caption for captioning all of my images. I have now noticed that after invoking \doublespacing ...
1
vote
0answers
20 views

Problem with \titleprefixword

I'm trying to make a songbook with Songs Package. The songs are in Spanish and I want to use the \titleprefixword macro to avoid sorting my song titles starting with the articles (El, La, Los, Las). ...
8
votes
3answers
245 views

write , instead of . in mathmode

in my language it's typical to write comma in numbers instead of a dot (12,34 instead of 12.34). However, if I write ",", it automatically inserts space right after the comma. To overcome this, I have ...
5
votes
1answer
113 views

How to forward a command parameter?

I am defining a new command and a flag with: \newcommand{\setActorsStyle}[1][1]{ \ifnum#1=1 \setActorsStyleColor{} \else \setActorsStyleBW{} \fi } \newcommand{\flag}{0} Calling the ...
0
votes
0answers
53 views

Apply macro to .tex file and get a new .tex file

Are there a preprocessor for TeX, like for C/C++? Are there a way to apply a macro to .tex file in order to generate new file? For example, I have macro: \renewcommand{asd}{some phrase here} I ...
1
vote
0answers
25 views

Different fnmark style in footer and text

I'm using the memoir document class and redefining fnmark like this in my preamble: \documentclass{memoir} \usepackage{footnote} \usepackage[bottom,hang]{footmisc} \usepackage{xcolor} ...
3
votes
1answer
63 views

Dump command as readable text?

Is it possible to dump the expanded form of a command as text? E.g. when I write a macro \newcommand{\mytest}[1]{\texttt{#1}} I would want to define a macro \mydump such that ...
3
votes
1answer
83 views

macro inside tikzpicture environment

When I take a part of a tikz picture out and put it into a macro, the code stops working. So, why does the following not work? \documentclass{article} \usepackage{tikz}\usetikzlibrary{matrix} ...
5
votes
1answer
132 views

problem with macro using \ifx

[Edit 1] originally titled "can't understand why this simple macro causes complex error" [original post] I've written a book, and now I'm trying to produce the e-book using tex4ht. Adapting this ...
0
votes
1answer
62 views

Where should I put LaTeX macro package files?

I'm preparing to submit an article to one of Springer's journals. It requires to use Springer's LaTeX macro package. (http://www.springer.com/statistics/journal/10985 --> Instruction for authors --> ...
1
vote
1answer
82 views

What is LaTeX's \if@nobreak mechanism for and how does it work?

many LaTeX sectioning-related commands have a block in manipulating the \@nobreak flag. Taking the following example for the sake of example: \begingroup \parindent \z@ \rightskip \@pnumwidth ...
4
votes
1answer
97 views

Providing optional key without value

I would like to prepare a macro with an optional argument like [wide], using xkeyval. (something whether to use \figure or \figure* inside) My test program below presents the output test0=false ...
1
vote
1answer
116 views

WinEdt cannot locate the specified .tex and .bib files

My laptop OS crushed and I did a fresh re-installation. I have installed WinEdit 8.1, 64-bit, and MiKTeX 2.9, 64-bit. However, I am trying to compile a TeX file but it returns the following error: ...
0
votes
0answers
31 views

Math display help [duplicate]

I need help for what command I should do. I have a sentence, and in the middle of the sentence I use a math stuff then, more words. The part with math is smaller and smushed up. I do not want to begin ...
0
votes
0answers
37 views

Why this macros doesn't work? [duplicate]

ALL i create this macro in my TeX file: \newcommand{\f2t}[2]{\label{#1}\footnote{\hyperref[#1]{#2}}} This macro is in order to return to text from the footnote when the reader click the footnote. ...
2
votes
0answers
64 views

How can I learn to make my own packages? [duplicate]

I can say I know how to create documents in LaTeX. However, I want to learn more. I would like to know how to learn to create my own packages. It may be a bit presumptuous for a beginner, but at least ...
0
votes
0answers
48 views

ComplexTable of Contents

Id like to create a table structure within my document based upon a \newlesson command for example. \newcommand{\newlesson}[1]{ \newpage \addtocounter{LessonNumber}{1}\subsubsection{{Lesson ...
1
vote
0answers
55 views

Typesetting “LaTeX” in LaTeX [duplicate]

There seems to be a macro for typesetting the acronym LaTeX, but I cannot think of manual to look it up or search term that would return relevant results. How can I typeset the word LaTeX as it ...
2
votes
0answers
55 views

Generating LaTeX reports from XML *without* external scripts

First of all, I apologize if this is pretty similiar in nature to my previous question: Reading and (custom) formatting a CSV (not \csvautotabular) I thought it would be better to separate the two ...
0
votes
0answers
31 views

Lilyglyphs how to design stem

I need to set a new command for drawing a minim with mensural notehead using LilyGlyphs. So far I have made a notehead which is a single character: \documentclass{article} \usepackage{lilyglyphs} ...
2
votes
1answer
55 views

Reading and (custom) formatting a CSV (not \csvautotabular)

Suppose I have a really long, really boring list of data in - let's say CSV, but converting to other formats is an option, when this can be done automatically - and I want to prepare a section in my ...
4
votes
1answer
150 views

Meaning of “\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip”

I am a novice of LaTeX, and I encounter the following code which I can't understand fully. \def\@dottedtocline#1#2#3#4#5{% \ifnum #1>\c@tocdepth tt\else \vskip \z@ \@plus.2\p@ {\leftskip ...
14
votes
3answers
408 views

Make macros with random (but specific) output

I try to find a way to make a \newcommand so that it has different outputs, that it chooses randomly. In the best case the macro should also avoid word repetitions (something like, only choose this ...
4
votes
1answer
81 views

What is the difference between passing optional and mandatory arguments?

I wanted to define a macro which makes a program listing, and finds out a program language from an optional argument. The output I receive from the MWE below is Language set = 'Verilog' Passed ...
3
votes
1answer
79 views

Why is it recommended to put \relax before \ifmmode?

I've several times seen the recommendation to put a \relax before \ifmmode in a macro. I've tried searching for an explanation of this several times on this site, but hadn't been able to find one. An ...
1
vote
1answer
67 views

Redefining \^ and \~ in math mode?

\^ and \~ apply accents in text mode, but each gives an error when used in math mode. So I consider redefining them for my own use, perhaps like this: \let\old@hat\^ ...
6
votes
1answer
36 views

Whitespace created in csname

I am using the newfile package to use an input file to insert figures, headings etc. Everything works fine, but a whitespace is created after the variable which is a problem if that variable ...
9
votes
3answers
190 views

Completely expandable loop macro that also works in tabular

Since I normally use tikz in my documents, I mostly use the \foreach \x in \list loop to repeat things. However, this famously fails in tabular environments and also everywhere where things must be ...
3
votes
1answer
50 views

new environment with one optional and second must have arguments

Probably this question has been asked before, but I could not find a satisfactory answer anywhere. Is there a way to define a \newenviroment with an optional and a must have argument. e.g something ...
5
votes
1answer
47 views

How to pass figure position to keyval macro?

I want to wrap a macro around figure-env to make my document more readable. Here is minimal example of how it is now: \documentclass[10pt,a4paper]{article} \usepackage{keyval} \makeatletter ...
3
votes
1answer
124 views

Xparse macro not working when \obeylines is in effect

This is the most strange and hard-to-debug situation I have encountered in latex. When \obeylines is in effect, it seems that macros with optional argument defined by xparse will have some trouble. ...
3
votes
1answer
33 views

How to re-define \space using \space in its definition

I am trying to implement a counter that counts the white spaces in order to give a rough estimate of the number of words contained in a paragraph. In order to do so, I set a new counter ...
5
votes
1answer
46 views

Avoid brackets with a command having an optional argument as subscript

I have the following code: \documentclass{article} \newcommand{\quot}[3][c]{\frac{#2}{#3#1}} \begin{document} \LARGE $A_\frac{a}{bc}$ $A_{\quot{a}{b}}$ $A_{\quot[d]{a}{b}}$ \end{document} If I ...
6
votes
1answer
156 views

Drawback of using a using a new command instead of \begin{something}?

Is there a drawback of defining and using a \newcommand instead of \begin{something}. e.g. if I use \newcommand{btkz}{\begin{tikzpicture}} \newcommand{etkz}{\end{tikzpicture}} \btkz \node{Hello ...
3
votes
2answers
91 views

returning maths values in a new command

So I'm trying to construct a command which calls another command to make typing easier, but for some reason I'm not able to get the commands to return things properly. Here is what I have ...
8
votes
3answers
308 views

Macro to close all open environments, groups and argument delimiters

Initial Request I am in search for a macro that would close all curly brackets and all open environments. Ideally, I could write something of the following sort: ...
1
vote
2answers
88 views

How can I run pdflatex on multiple .tex files on Windows 7?

I built some graphics with TikZ and pgfplots. I have put the code with the most minimal necessary preamble into a standalone document for each figure. Say I put all those files for chapter 3 (hence ...
6
votes
1answer
42 views

arithmetic expression involving command

Simple question. I would like to do this: \newcommand{\scatterplotwidth}{0.5\linewidth} .... \includegraphics[width=0.9\scatterplotwidth]{myfig} Without the 0.9 it works. Is there a way to have ...
6
votes
1answer
77 views

Different result using \newcommand and \NewDocumentCommand

I am writing a text which references a whole bunch of Brazilian norms. All of these norms are prefixed with "NBR". I therefore created the following command \newcommand*{\NBR}[1]{NBR #1\cite{NBR#1}} ...
7
votes
2answers
173 views

Associate counters — stepping (many) counters simultaneously

This is (perhaps) not a real question and there maybe already an answer to my proposition/request. The situation There are packages that provide the number of the last page (i.e. lastpage or the ...
0
votes
0answers
23 views

Nested definitions [duplicate]

I have the impression that if one defines a macro inside the definition of another one, then #1 and so on indicate the outer macro's arguments, while ##1 indicates those of the inner one. Is that ...
10
votes
2answers
219 views

Can I define a command with optional argument coming after the mandatory ones?

Is it possible to define new commands having the following form: \command{<marg>}[<oarg>] I have seen commands of this form in the fontspec package. But not sure how to achieve this.
4
votes
1answer
48 views

mtpro2: PARENS environment error

\documentclass[10pt,a4paper]{book} \usepackage[utf8x]{inputenc} \usepackage{ucs} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage[lite]{mtpro2} ...
15
votes
1answer
431 views

What does \@car do?

The title says it all. I'd like to know what \@car does. I came across it reading through the source of the hyperref package, but it doesn't seem it's defined as part of the package. I tried Google, ...