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

8
votes
3answers
176 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 ...
2
votes
1answer
35 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 ...
4
votes
1answer
71 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 ...
1
vote
1answer
46 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
53 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\^ ...
8
votes
3answers
163 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 ...
1
vote
1answer
54 views

Bold and Italic texts styles are too big

I have a problem with my \textbf and \textit commands, it makes my texts bigger than when no styles are applied. An example is shown here: I also put an URL inside the bold command ...
6
votes
1answer
27 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 ...
0
votes
0answers
37 views

Undefined Control Sequence on using defined \newcommand [on hold]

At the beginning of my document I have defined a few commands: \documentclass[a4paper]{article} \usepackage{amssymb,a4wide,graphicx,float,amsmath,epstopdf} \graphicspath{ {/build/} } ...
3
votes
1answer
118 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. ...
0
votes
1answer
63 views

Graphics: Moving Images and aligning with text

So currently I have this code written out: \begin{figure}[ht!] \includegraphics[width=60mm, scale=0.3]{titanium-distillation-vessel.jpg} \caption{Argon Vessel, containing TiCl$_{4}$ and Mg} ...
14
votes
3answers
214 views

How to define a new command based on \section with its optional argument?

I've defined a new command called \mysec like the below: ‎‎‎‎‎‎ \documentclass{article} \newcommand{\mysec}[1]{\section{#1}} \begin{document} \mysec[Foo foo]{Bla bla bla} \end{document} But in the ...
3
votes
1answer
45 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
44 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
30 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 ...
8
votes
3answers
462 views

Determine last day of given month

I want to determine how many days there are in a particular month. Using the datenumber package, I thought I could simply set the date to the 1st of the next month and then back up one day would be ...
6
votes
2answers
118 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 ...
7
votes
3answers
266 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: ...
5
votes
1answer
43 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
2answers
130 views

Delimited arguments and using a macro inside of itself

I wanted to play with delimiter sizing without using the \delimiterfactor, -shortfall, etc. and made the following: \newdimen\bigdim \bigdim = 1.9743ex \newdimen\Bigdim \Bigdim = 2.671ex ...
6
votes
1answer
140 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 ...
1
vote
2answers
70 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 ...
3
votes
1answer
42 views

AucTeX insert-environment C-c C-e (no label prompt)?

Does anybody know how to configure Emacs or Auctex such that when you insert an environment for example with C-c C-e equation RET? Avoid having to type RET for (Optional) What label? question? Or ...
3
votes
2answers
87 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 ...
17
votes
4answers
507 views

Extract the numerical and non-numerical portion from text

I would like to extract the leading number and subsequent text from a string. I have an idea of using the xstring package to gobble characters from the right until I end up with a number or an empty ...
1
vote
1answer
87 views

Add index item by makro

I am struggling with creating a macro that would enable me to create index items by macro. From a former post (LaTeX: is it possible to create a macro to add words to index (using TexMaker)?) I have ...
6
votes
1answer
40 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 ...
10
votes
2answers
200 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.
6
votes
1answer
68 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}} ...
0
votes
0answers
22 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 ...
4
votes
1answer
43 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} ...
21
votes
2answers
854 views

Lisp relics in LaTeXe logo

I always thought TeX's macros are very Lispy like and stumbling across the definition of the LaTeXe logo confirmed it. The macro is defined as follows: %\LaTeXe The LATEX2" logo as proposed by A-W ...
15
votes
1answer
420 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, ...
12
votes
3answers
400 views

Macros that know their macronames themselves?

Some programming or scripting languages know the feature of #0 or $0, holding the name of the current script or the current routine. Does a similar technique (or a workaround) exist for the macro ...
3
votes
2answers
49 views

How do I output “dumb” apostrophes with the sffms package?

I'm using the sffms package to typeset a book manuscript (using the version of the package shipped with TexLive 2013 on a Mac). I want to output both double and single quotes so they are "dumb" or ...
18
votes
1answer
245 views

Is it possible to define a command taking an optional star and working in a subscript?

Note: this is more or less a cross-post from my blog. I hope this is acceptable, especially that this is a genuine question! I’m currently writing a (longish) document on mathematics. Among other ...
29
votes
5answers
3k views

Stop LaTeX compile with a command?

Is there a way to stop the compile process through the use of a command? Something like: \exception{This is a user-set exception. Compile halted.} So when performing the compile process, the ...
0
votes
0answers
29 views

Follow Up Question : multiple lines format for ifthen or ifbool compound statements

Follow up question to How do I add multiple macro definition inside an \ifbool compound statement? Ok if you look at the last post, people fixed my format for the ifthen / ifbool statement format to ...
1
vote
1answer
21k views

\Latex{} : undefined control sequence

I use teXworks and I have a file called textwork1.ltx. Here is the code: \documentclass{article} \usepackage{amsmath} \usepackage{amstext} \usepackage{amssymb} \usepackage{graphicx} ...
3
votes
0answers
35 views

A mysterious blank line come from an \hskip?

I use a very complicated .sty file. The main purpose of this .sty is to enable a special inline box in which texts can be typeset in a very special way. There is no problem inside the box. The .sty ...
32
votes
3answers
1k views

Removing the spaces between words

Is there any way to remove spaces from in between the words in a text? Something like \RemoveSpaces{This is my sentence.} which will be converted to Thisismysentence.
38
votes
2answers
6k views

What does \ifx\\#1\\ stand for?

The following usage of \ifx can be found in several packages and also in answers on this site. What does this syntax exactly mean? Are there any alternatives and drawbacks? ...
13
votes
1answer
264 views

How to execute a command only on the next run?

Let's say I have a command \foo that I want to execute only on the next run of TeX. How do I create a command \onceFoo that does this? (It is also permitted to execute \foo if the aux file has been ...
7
votes
2answers
251 views

Is there any analog to #pragma once in (La)TeX?

In C, I can write #pragma once as a preprocessor directive at the top of a header file, which tells any compiler that supports it to include the file a maximum of one time per compilation cycle, ...
5
votes
4answers
148 views

Alignment of the text like a table

What I wanted to achieve was this: I defined a new command like this: \newcommand{\details}[2]{ #1 \hspace{2cm} : #2 \\ } The full MWE is as follows: \documentclass[12pt]{article} ...
3
votes
1answer
100 views

How to Define New Todo Command Which Still Takes Options

I am using the package todonotes in order to handle my TODOs. As written in the manual, one can define a custom TODO command like that: \newcommand{\feedbackRequired}[1]{\todo[color=red!70]{#1}} ...
3
votes
2answers
49 views

How to expand a macro to use it inside a question in AMC?

Context I'm trying to use AMC to produce an exam with code in it. However, the use of verbatim code inside the questions is beyond the scope of the package. They suggest to declare boxes and used ...
2
votes
0answers
30 views

\newcommand - Missing \begin{document} [duplicate]

On defining a new command, and using it, LaTeX throws an error that Missing \begin{document}. What is the issue here? \documentclass[12pt]{article} \newcommand{details}[2]{ #1 \hspace{2cm} : #2 } ...
0
votes
0answers
24 views

How do I make a new command with author/journal/year citation in footnote

\documentclass{beamer} \usepackage[backend=bibtex]{biblatex}%backend=biber, natbib=true, style=chem-acs \bibliography{oralspaper} \DeclareCiteCommand{\citejournal}%%%creating \citejournal command ...
7
votes
2answers
87 views

Redefine \newcommand to insert code at start and end of custom macros

I would like to be able to insert code into the definitions of my custom macros, without having to modify each macro definition. This seemed like a simple case of redefining \newcommand, but this ...