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

2
votes
1answer
51 views

Forloop with tikz-cd

I am trying to write a macro that (for now) takes as input a number n, and outputs a tikz-cd diagram consisting of n consecutive arrows. However the following code leads to an error: You can't ...
3
votes
1answer
165 views

Why does declaring a command in-document produce horizontal space?

I'm really confused about why there is some extra horizontal space that appears before the second "Test" on my second line: \documentclass[12pt]{article} \usepackage[english]{babel} \begin{document} ...
0
votes
0answers
33 views

What does mbox and fbox stands for? [duplicate]

what does \mbox and \fbox stands for? I felt that it's easier to remember macros when I know what they stand for.
1
vote
1answer
28 views

change caption of multiple listing styles

I want to have different listing environments, each with an own caption. My try was this (vorlage.tex): \documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch \usepackage{...
1
vote
0answers
68 views

Using /csname in

I want to use a smarter solution for a big CSV file with many LocalX columns \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} %\usepackage[utf8x]{inputenc} \usepackage[...
13
votes
3answers
342 views

Defining a command to define an asterisk command

I have the following command \defmeta that defines two other commands (one starred and one unstarred) \documentclass{article} \usepackage{suffix} \newcommand{\genericcmd}[3]{#1 #3 #2 } \newcommand{\...
2
votes
1answer
40 views

Pre or post process some node's options (nodes in node and main node labels)

For setting sub nodes in node I use the following code (provided by Mark Wibrow): \documentclass[border=3mm, tikz, preview]{standalone} \makeatletter \def\...
3
votes
2answers
84 views

Escape hash tag in strings passed to newcommands

I have been trying to write a simple new command to make a piece of code more flexible and readable (a MWE is below). In it I need to be able to pass a string to a new command that contains a hashtag ...
1
vote
1answer
63 views

Environment inside \newcommand [duplicate]

This is my first question so feel free to correct it in any way. I am struggling with the following problem: using an environment in a \newcommand. I want to define the command \describe this way: (...
1
vote
1answer
52 views

Active character in a command

I would like \forall to trigger a certain behavior (for the purpose of the example below: change the text color to red), which is cancelled when the next ( is encountered. I can make this work when ...
3
votes
2answers
41 views

Avoid recursion in \renewenvironment

I'm trying to redefine an environment in order to add a command after the \begin without having to add this command in manually everywhere. For example, I'd like to replace every instance of \begin{...
2
votes
1answer
38 views

Getting user defined constants into the preamble

I think this is a problem of expandable content, a concept I haven't quite got the hang of yet... Lets say I have a preamble or cls file that is trying to configure hyperref. If I have manually setup ...
12
votes
4answers
428 views

High-order recursive macro to define several similar macro at once does infinite loop

I’m a fan of factorization and hate code repetition. So I was trying to define a macro which defines for me all the common mathematical sets commands (\C, \N, etc.) and made a recursive function ...
6
votes
2answers
113 views

Is there a modal command for MakeLowercase?

Analog to this question I've been wondering WHAT is to \lowercase as \bfseries is to \textbf? (... and for uppercase, or \MakeLowercase and MakeUppercase, etc., which also seem to be text-block ...
3
votes
1answer
38 views

Different command definitions with and without optional argument renders incorrectly

I used answers given to this question (in particular, this answer by egreg) to come up with the following code: \documentclass{article} \makeatletter \def\ifemptyarg#1{% \if\relax\detokenize{#1}\...
2
votes
1answer
41 views

Mark lines like overfull

I apologize if this has been asked before. I have searched and searched to no avail, it seems questions about getting rid of over/underfull boxes drown out any questions about how to produce the marks....
2
votes
1answer
42 views

\def'ed plain-text argument behaves differently from plain text

So this is my example, closely related to Remove extra curly braces. Apart from my application, trying to line-break the labels in the margin even if they do not have spaces in them, I am trying to ...
2
votes
0answers
40 views

Bullet and alignment issue in itemize environment [closed]

Itemize environment under the macro is not showing bullet. It's showing dash. Also, there is an issue with horizontal alignment. It's not aligned properly. I already fixed with by using \begin{itemize}...
1
vote
0answers
14 views

Tikzcd withing newcommand? [duplicate]

I want to define a new command using the package tikz-cd. For example, suppose I want to define: \newcommand{\simplearrow}[3]{\begin{tikzcd} #1\arrrow[r, "#3"'] & #2 \end{tikzcd}} This would ...
1
vote
1answer
41 views

Passing a macro to a vector declaration in tikz/pgf

Inspired by an answer I gave here, the question arose how I need to properly define a macro, if I want to pass it to a vector declaration in tikz. If you want to modify a vector, the syntax used is ...
4
votes
0answers
99 views

Getting negative vspace to behave

My TeX code (including parameters in command definitions) that creates lyrics sheets and chord sheets of songs is generated dynamically by other code accessing database data and processing it line by ...
4
votes
4answers
102 views

Generating a table from key-value pairs

I want to automatically generate a table from a comma separated list of key-value pairs such as {{x=1,y=2},{x=3,y=1},{x=2,y=3}}. In each "row" the "keys" are always the same (they become the column ...
8
votes
2answers
735 views

Own mathematical function f(x)

I'd like to define an custom function f(x). For example \f{3} should print ln(3) + 3 if the function is set to ln(x) + 3. One should be able change the function: \setfunc{sin(\x}}. This should only ...
1
vote
1answer
56 views

Convert text from mixed case to start case

I'd like to change the capitalization of a macro from mixed case to start case. Let's say the following macro is already defined: \newcommand{\tostring}{toString} I can change the first letter to ...
2
votes
1answer
110 views

Command macro for an environment

How can I define a command macro using \newcommand so that the argument to the command is surrounded by an environment?
2
votes
1answer
50 views

table layout inside a newcommand

I wonder if I can define something similar to the \newcommand that places the values inside a pre-defined table (tabular) template. If you see the table above, imagine you would duplicate that many ...
1
vote
0answers
53 views

How to pass a color as an argument [closed]

Before explaining my problem, sorry if this is a repeated question, but I was not been able to find one answered/asked question in which the problem was the same as mine. In order to create a ...
3
votes
1answer
94 views

Bulk letter, “loop” doesn't work, “read to” doesn't work

Original Text below Edit: I solved it with endless googleing and help from here. Here is my theory: the typos caused expandafter to fail, which caused a dismatch between the chopline command and the ...
4
votes
1answer
66 views

Can't use macro in square brackets

I've made a matrix in a beamer presentation and I'm trying to style the nodes. \newcommand\foo{row 1/.style={inuse}} \begin{frame}{Chunks} \tikzset{ inuse/.style={text=red}, free/.style={...
2
votes
1answer
91 views

Get key value of command

i'm beginner in Tex and i have tex file \documentclass{article} \addtolength{\jot}{1em} \begin{document} \begin{verbatim} \end{verbatim} \begin{chestnutStem} In the following figure, if the ...
11
votes
3answers
568 views

Repeat characters n times

I wanted to create a new command, which allows me to repeat any characters I want for n times. After some searching and trying, I came up with this: \usepackage{multido} \newcommand{\myrepeat}[2]{% ...
6
votes
3answers
125 views

using csname to define intern commands(variables) and their setters

I want to define some macros to create texts in different languages; the command is \newlang which creates an invisible macro or variable to store the text of the specific language and a setter to set ...
3
votes
1answer
47 views

Passing a newcommand with one argument to another newcommand

I am wondering how to define a new command A with another new command B (which has one argument x) as the argument of A. Here is a simple example: \documentclass[english]{article} \usepackage[T1]{...
3
votes
1answer
23 views

How to get xcolor colour mixing to work in newcommand

I want to set the colour of a table cell using the argument passed into a command, but it doesn't seem to have any effect. Here's my code: \PassOptionsToPackage{table}{xcolor} \documentclass{beamer} ...
4
votes
1answer
46 views

Line breaking in \newcommand

I defined a new command for highlighting some text parts: \newcommand{\keyword}[1]{\colorbox{black!5}{#1}} Unfortunately, when the text becomes to long it overlaps my margins. The keyword ignores ...
1
vote
1answer
31 views

pgfplots filter table with float content and conditions

I want to filter some data for a plot, and so far the best thing I found is this here. This is the relevant code from the mentioned question: \pgfplotsset{ discard if not and smaller/.style n ...
2
votes
1answer
80 views

Replace undefined reference ?? with custom text?

I'm using luatex and the cleverref package while writing a large document. I often only want to compile only parts of it, but I'd like my output to be a little nicer when I only compile a single ...
6
votes
1answer
49 views

Keep babel's automatic spacing in \newcommand

In French, there's a narrow non-breaking space before ":". These are automatically added by the babel package, of course. However, I noticed something strange: the following macro \newcommand{\abc}{...
1
vote
1answer
51 views

Styling \Blindtext and \blindtext (aka renewcommand with optional arguments)

I am using blindtext package to draw out how the layout of the document will look like and then swapping the "dummy" parts with real text. Problem is that I would like to give some style to these text ...
1
vote
1answer
39 views

Generate list of macros in the output

I have several macros defined in my document. \newcommand{\pa}[1]{\left(#1\right)} % enclose with parentheses \newcommand{\bra}[1]{\left[#1\right]} % enclose with square brackets \newcommand{\pfrac}[...
0
votes
0answers
39 views

Issue with underscore inside a newcommand for math mode

I have this new command as a shortcut for math mode: \newcommand{\m}[1]{$ #1 $} I get the error Missing { inserted error on lines including underscores like \m{f_1(x) = 10} and \m{f^2(x) = ...
6
votes
3answers
165 views

Make Characters Active via Macro in Math Mode

I am trying to make characters active in math mode, but can't seem to get past the most basic of examples. I would like to define a macro which is passed: the character to make active and the ...
1
vote
1answer
66 views

Macros just for certain number of lines

I want to write a macro that will do certain things with a fixed number of lines coming after this macro. For example, how to apply \rightskip=2cm to the first four lines of a paragraph How to ...
2
votes
1answer
44 views

using \dq in \subsections: has an extra }

I defined \newcommand{\q}[1]{\dq#1\dq} for the easier usage of the quotes. Now I want to make subsections containing quotes... \subsection{ \q{build} } This line above causes an error for l.42 ......
0
votes
0answers
59 views

New command to append endings on labels via \gls

The \gls-like commands of the glossaries package allow to append a text after the referenced label. In addition, the package includes the command \glsaddstoragekey to add additional informations to ...
2
votes
1answer
57 views

Modifying \coadvisor command

I would like to modifying the command \coadvisor in my thesis. Now when I use it I get: Co-orientador: Fulano de Tal After modification, I would like to get: Coorientador: Fulano de Tal ...
1
vote
1answer
34 views

Making csv2latex work with OSX El Capitan and TexMaker

I have encountered several difficulties making csv2latex work after excel2latex mysteriously failed after having worked fine for 2 years (no upgrades of office or anything)... I am using TexMaker as ...
4
votes
2answers
68 views

Newcommand inside foreach: multiple arguments and minipage environment

I am trying to define multiple, sophisticated newcommands within a foreach loop. This sounds so simple, but why is it so hard ? Naive attempt: \documentclass{report} \usepackage{tikz} \foreach \i ...
2
votes
2answers
52 views

Tikz macro with calculation error

I'm very new to this so bare with me. To get the hang of macros I wanted to write a simple command to draw a square in tikz. Now I know there are a lot of ways to do this, but I want to be able to ...
2
votes
1answer
73 views

Formatting matlab code within a macro

I know there have been a number of posts relating to this topic, in particular this one, but I find it impossible to believe that it's simply impossible to do the following incredibly basic thing ...