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

9
votes
1answer
2k views

TikZ: \newcommand with optional TikZ options

I want to create a new command with some default TikZ options that you can override using an optional argument. If working as intended the code below would generate a red line between A and B, and a ...
14
votes
1answer
234 views

What practices are there regarding the use or avoidance of “internal” TeX or LaTeX commands?

What practices are there regarding the use or avoidance of "internal" TeX or LaTeX commands? (About "command" vs "macro", there is some discussion in this TeX.SX answer, though I don't know whether ...
7
votes
2answers
198 views

newcommand conditionals

I am looking to create a command that adjusts my page layout, here is a sample: \newcommand{\margin}{ \pdfpageheight 297mm \pdfpagewidth 210mm \pagebreak \newgeometry{lmargin=31.5mm, rmargin=31.5mm, ...
18
votes
1answer
726 views

What does the # symbol do in LaTeX?

I know most of the effects of the special characters in LaTeX, like \ is used for most commands, or $ is used for opening or closing the math ambience, but I don't know what the symbol # does, and I ...
13
votes
5answers
278 views

Two independent optional arguments for new commands

I'm trying to adapt the solution provided in Different command definitions with and without optional argument to change the behavior of my new command. I'd like to use basic command to avoid some non ...
3
votes
0answers
36 views

Unexpect differences between calling \ifmmode from within a command and outside a command [duplicate]

In answering another question regarding testing for math mode, I proposed the following command \newcommand{\testa}{% \ifmmode ^{12}\text{CO(1-0)}% \else $^{12}$CO(1-0)% \fi } But ...
8
votes
2answers
190 views

Macro with environmental dependent output

I'm trying to develop a macro that gives two different outputs depending on whether it is in math mode (i.e. $ $ or \begin{equation} ... \end{equation}) or anywhere else. The reason is that I use a ...
9
votes
3answers
1k views

Using counters and \ifthen in a macro: what's wrong?

I have (made, actually) a graphic of the forepaw-print of a bear that I want to use as a flourish mark at the end of chapters and a few other places. After finishing with the image, I created a mirror ...
2
votes
1answer
338 views

xstring StrSubstitute and table

I got a problem with xstring \StrSubstitute in combination with a table. I would like to replace newline (\\) in a variable with the \newline command to generate a second line in a paragraphed table ...
5
votes
1answer
289 views

Macro for set intersection

I want to create a macro for intersections that can switch between cap and bigcap depending on the situation. Here is what I came up with based on browsing other posts on the forum. Are there any ...
5
votes
1answer
252 views

Including .tex files that need a different style file than the main text

EDIT: Substantial edit of the original version has been done to clarify the question. Background I've written two small python package manuals with sphinx (http://sphinx-doc.org/) a program that ...
5
votes
1answer
322 views

How to preserve lenghts to use with \includegraphics scaling, when calculating them with pgf

This question is related to my earlier question here: How to define a macro that uses image width and height to define a variable for later use . There you can find a full MWE of the problematic code. ...
5
votes
1answer
225 views

lstlistings in defined Tikz box

I have created a box using \newcommand, based on TikZ named "mybox". The equation easily insertable in it. But I want to insert a \lstlisting environment in it. But it doesn't work. How can I do it? ...
8
votes
1answer
280 views

How to define a macro that uses image width and height to define a variable for later use

Ok, the title might be a bit cryptic and my question is a bit lengthy, so please bear with me. What I want to do is: I have two images with different aspect ratios that I want to place next to each ...
0
votes
1answer
413 views

Cross out the selected text using macro script in TexStudio

I have a Tex file that I need to edit while somehow keeping the original words and sentences highlighted. To do this, I am going to cross out the part of the original text that I replace with my own ...
0
votes
1answer
125 views

glossaries and REnewglossaryentry

I haven't found anywhere and I wonder is there or would it be very hard to provide a command \REnewglossaryentry[2] for the glossaries package. Name for the desired command is kinda self explanatory, ...
4
votes
1answer
204 views

Are there any programs that will attempt to preprocess simple LaTeX?

I find myself in the awkward, although apparently not uncommon, position of being ordered to write, or at least end up with, documentation in the Word format. I don't have anything that fancy in my ...
2
votes
1answer
507 views

'Undefined control sequence \setkomavar'

I ran into the error: 'Undefined control sequence l.12 \setkomavar{subject}{Regarding: Code 123.456}' My document preamble looks like this: \documentclass{letter} \usepackage{hyperref} ...
6
votes
1answer
871 views

How to use \ifnum for arguments (expanding macros)?

I want to count my section's, figure's etc. using the totcount package. To get a general useable template I want to show only counters which are larger than zero. But it seems that total{counter} ...
10
votes
1answer
120 views

Plain text index via pdflatex

I would like to obtain a plain text version of the index so thought it might be easier to extract it from the existing packages somehow. The MWE below produces: What I want is a text file ...
3
votes
2answers
403 views

Macro for Typesetting Semantic Denotations (Linguistics)

I tried to write a macro for typesetting semantic denotations, using the stmaryrd package, but there are a few issues that I would like to resolve. My first attempt at the macro was the following: ...
3
votes
1answer
229 views

Enlarge small caps and memoir headers

I enlarged the small caps of my font by using the letltxmacro package. This works fine in text, chapter titles, etc., but I'm using the \pagestyle{ruled} under memoir which causes even page headers to ...
6
votes
2answers
136 views

Problem with newly defined command and special chars

I have the following problem. In my document, I defined a new command to save a few chars \renewcommand{\r}{r_\mathrm{max}} Additionally, since it is Swedish, it makes use of the special char å, ...
10
votes
2answers
216 views

How to create command that creates new if command?

I want to load parameters (for conditional compilation) from files. I wrote command param that creates new if command and read parameter from file, containing following line: \paramnametrue % or ...
5
votes
1answer
1k views

define an global variable; error ! Use of \@ doesn't match its definition

I want to define some variable for my IPE template, such as the title, affiliation and author etc. The code is listed below. However when I compile it using pdflatex, it does not show the result what ...
0
votes
0answers
67 views

Declare macro for simple text snippets [duplicate]

I want to use something like this: \newcommand{\favouritealgorithm}{\texttt{Gaussian elimination}} so that My favourite algorithm is \favouritealgorithm written in C. produces My favourite ...
4
votes
2answers
113 views

Define a macro expanding into quotes

I need a macro that expands an argument into the string { "argument"}. The following macro seems to do the trick: \newcommand{\myquote}[1]{\{ "{#1}"\}} This macro produces for the input ...
4
votes
3answers
783 views

Passing image path to \includegraphics using a macro

I'm trying to use a single environment for a number of different cases. For each case, I need the environment to have a different image associated with it. When I try this, I get ! LaTeX Error: ...
4
votes
3answers
278 views

What's a better way to define individual link colours for a url in a macro?

I've got a document where I'd like two colours of links - cyan for links in headers that since it's brighter, and navy blue for links in the main body which is more subtle/less distracting. I already ...
2
votes
1answer
459 views

\raisebox command for subscript [duplicate]

I was wondering if anyone know make a command for raisebox subscript? This question asks how to make the subscript part...here I want to make the command shorter by having a macro do the work rather ...
4
votes
1answer
69 views

Access values within \newcommand

I am a LaTeX user with moderate experience. However, I am trying to create my own .cls file for the first time. I would like to produce a header in a similar fashion to how title is produced in ...
5
votes
2answers
81 views

Embedding \soulomit in a macro

In the MWE below, the code: \MyUl{abd \soulomit{\MyLink{www.google.com}{The Google}} ghi} works exactly as desired: However, when I attempt to wrap this in a macro, and use \MyUl{abd ...
13
votes
2answers
201 views

An hbox-vbox-halign permeable macro, is it possible?

I currently have a Plain TeX file which does something like this in a multitude of places: \indent\hbox{\vbox{\halign{#\hfil\quad&#\hfil\cr ... table content here ... }}} I would love to ...
8
votes
2answers
99 views

Eat double space

How can I get a command to eat an unnecessary space, consider the below: \documentclass{article} \newcommand{\mycommand}[1]{#1} \begin{document} %Creates single spaces Discussed ...
3
votes
2answers
568 views

TexStudio Commands on mouse over quickly disappear

I have installed miktex 32bit and texstudio on my windows 7 32bit laptop. Whenever I mouseover a command like tabular in the example \end{tabular} the tooltip shows up for some millisecs and ...
16
votes
3answers
368 views

newcommand does not work with \fi

I tried the command \newcommand{\fistudenti}{\fi} but it seems to work properly only in some cases. Here below there are two insances when it works and when it does not: WORKS: ...
2
votes
1answer
136 views

Using data from tabulary to typeset columns

While trying to write a better answer to this question, I've made several (probably quite bad) attempts to use the tabulary environment to typeset paragraphs to try to in some way be able to split a ...
12
votes
2answers
752 views

create a framed environment for a margin note

What am trying to achieve is the following: Of course, if this can be done so that there is a switch between even and odd pages. Currently I am only interested in the not appearing on the LHS ...
4
votes
1answer
391 views

Converting string to number

I am trying to write an environment which provides (some of) the functionality parallel environment through tabular syntax so that the following two code snippets would give equivalent results: ...
5
votes
3answers
422 views

Using \ifstrequal in a fontspec macro

Here is my Minimal Failing Example: \documentclass{article} \usepackage{fontspec,etoolbox} \setmainfont{TeX Gyre Schola} \begin{document} \newcommand\Stretch[1]{ \ifstrequal{#1}{narrow}{0.6}{} ...
10
votes
1answer
146 views

Is it possible to embed section titles within subsections?

I would like to to do the following \section{Animals} \subsection{Mammals} \subsection{Birds} and have it result in 1 Animals 1.2 Animals>Mammals 1.3 Animals>Birds I have tried to do this ...
8
votes
2answers
420 views

xparse and key value arguments

I'm trying to learn how to do macros. I want to use xparse as it seems the most powerful tool. I also want named arguments, as numbered arguments make me, as a programmer, uncomfortable. I had some ...
1
vote
0answers
290 views

Insert code snippet via keyboard shortcut in TeXworks

I know there already are questions (1, 2) on creating keyboard shortcuts in TeXworks. The discussion (also in the Google thread referred to), however, seems a little outdated. By now, there is the ...
3
votes
2answers
88 views

Replace and add a/to a specific sequence of tokens

Is there a way to find a specific sequence of tokens and add after it a command? Or is there a way to find a specific sequence of tokens and replace it with another one? And do it only if the sequence ...
1
vote
2answers
257 views

Spacing depending on optional subscripts and superscripts

I am totally new to LaTeX (use it for 2 days), so I am sorry if this has already been asked, but I spent the last 6 hours searching for a solution, but to no avail. (I stumbled upon a package xpeek ...
5
votes
1answer
319 views

Can a \newcommand Definition Contain Braces as Substitution Text?

The following example is completely counter-intuitive, but I need this in a bigger definition I'm not including here. \newcommand{\openbrace}{{} I need this to start a nested scope. Is this ...
3
votes
2answers
146 views

Using \color in a paragraph column inside a tabular environment results in a line break [duplicate]

Some of my documents are compiled into multiple outputs. Some Versions contain certain parts, while other versions contain only a placeholder. For this purpose I have a macro \markup that colors its ...
29
votes
2answers
446 views

How to design a command inquiring internally required packages?

How can I define a document command \FilesRequire that writes to the .log (or to the output console) a list of all packages internally required by the declared document class and by the packages that ...
3
votes
0answers
813 views

Texmaker. Color in the editor. Math mode [closed]

I am starting to use Texmaker with the default configuration. When I use the math mode ($...$) all of it is coloured in green in the editor, making long formulas difficult to follow. I would like ...
3
votes
3answers
103 views

Selecting grammatical form depending on programatically defined cardinal number (a la ngettext)

There are many languages where grammatical form depends on number of elements described. In English it is singular and plural form (plural usually but not always is generated by adding suffix 's', ...