{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
2answers
98 views

Collecting contents of environment and store them for later retrieval

I want to store contents of an environment and add them to a macro or command I could easily retrieve them, but I do not want to use the collect package. Are there any alternatives? ...
7
votes
1answer
104 views

How do you define macros to toggle a character active and define a macro for it?

I'm experimenting with core tex in order to learn some basics. My goal is to define a shorthand environment which makes use of active characters. The general idea is to activate the used characters ...
2
votes
2answers
56 views

How to write macros that behave like \item in an enviroment?

I am attempting to add an environment to a project that would take the following form: \begin{example} \source some text goes here to be used as an example. \target some more text goes here as a ...
7
votes
1answer
74 views

Passing values to a command

I am new to Tikz and have been largely following the PGFManual to learn about how to use it correctly. The PGFManual shows examples of using foreach but they do not show how to pass it to a command. ...
3
votes
1answer
57 views

\newcommands in the \standalone file not recognized in the main file

Few \newcommands defined in my standalone .tex file containing tikz figure is not recognized in the main beamer .tex file. Please point out what extra lines should I write to make it work. Here is ...
30
votes
3answers
2k views

Why are LaTeX macros so inconsistent?

I use LaTeX daily to write my papers, and while I find it a very nice tool to make documents in, some things about the system outright bother me; such as the very inconsistent macro system. A few ...
1
vote
0answers
52 views

macro: repeat a command if new page else do nothing

QUESTION: How does one write a pair of macros that work in 1) beamer class and 2) article class, respectively, such that if it, \macroname{...}, is executed at a point in the code, that point ...
3
votes
1answer
30 views

Creating command: FanceVerb Error, Paragraph ended before

Hi and sorry if that question might be already asked. I try to create a command like this: \documentclass{scrbook} \newcommand{\code}[1]{\texttt{#1}} \newcommand{\smallx}[1]{ \begin{center} ...
6
votes
1answer
108 views

How can I throw a custom error from \newcommand

I'd like to write a command that checks the given arguments and throws an error if they are not in a range. I'm imagining this would look something like this: \usepackage{xifthen} ...
1
vote
1answer
59 views

An inconsistency in beamer color handling: how to set color for a specific slide layer?

The following MWE works for setting the color of the bullets, but not the \item text (except at the top level, which turns everything grey). As I step through the slides, I'd like the text of the ...
1
vote
0answers
21 views

Dummy macro for ignoring beamer overlay

I would like a dummy macro that ignores overlay specification (from beamer) when the code is copy-pasted into another class. \documentclass{article} \usepackage{fontspec} \newcommand{\onslide}[1]{} ...
1
vote
1answer
59 views

LaTeX tokenizing

With LaTeX macro \newcommand{\CH}[2]{#1\choose#2} and input \CH63=20 my hope was to get the equivalent of {6\choose3}=20 but I get {6\choose3=20} instead. I know how to fix the text to ...
1
vote
1answer
94 views

fit tikzpicture to page width or height (using macros)

I have a new environment defined that fits tikzpicture to the page width, but when tikzpicture is long in height the bottom part of the tikzpicture is cut and extra blank page appears because of the ...
8
votes
3answers
179 views

Automatic three digit numbers in subsections

I'm a newbie in LaTeX, please forgive me if this is too stupid. I have some code like this: \documentclass{article} \newcounter{qnumber} ...
5
votes
2answers
87 views

How can I force lstlisting to expand an argument?

I'm trying to use the listings package with a variable language (it's actually for a package). However, I can't seem to pass a macro as the value half of a key-value pair. Here's a simple example: ...
3
votes
1answer
56 views

TeX commands and currency symbols

Why does the code \documentclass{memoir} \usepackage[latin1]{inputenc} \usepackage[danish]{babel} \usepackage[T1]{fontenc} \def£#1£{``#1''} \def€#1€{<#1>} \begin{document} Hi, £this£ is nice, ...
3
votes
2answers
197 views

Macros formatting/arranging words {A_1}{A_2},…{A_n} into predefined paragraph for varying n and tagging

How does one robustly (without breaking most environments) construct the macros with arbitrary number of parameters that output the parameters into a predesigned paragraph such that several of these ...
7
votes
4answers
93 views

Ignoring arguments passed to a command depending on the number of arguments specified

Consider the following code: I'm trying to write a \newcommand that will accept either m or n arguments, where m < n. Here m=4, n=6. I want to set things up so that if I call a newcommand, and it ...
5
votes
1answer
65 views

How to store tcolorbox's (multiple) settings in a macro?

I'd like to store tcolorbox' (multiple) settings in a (single) macro (in fact, a xkeyval's \cmdKV@fam@key macro) and use them afterwards via this macro (I know I should use pgfkeys instead, but my ...
7
votes
4answers
206 views

auto-detect conditional probabilities in macro

Is it possible to write a macro that detects whether there is a | character in its arguments, and expands that to something else? In concrete terms, I want to be able to use the following definitions ...
5
votes
1answer
151 views

\pdfoutline, German sharp-s character

I use the following code to produce bookmarks in a pdf document: \pdfdest num 1 fit \pdfoutline goto num 1 count 0 {äöüÄÖÜß} äöüÄÖÜß ... more text ... The text prints fine. The pdf bookmark shows ...
4
votes
3answers
103 views

Macro concatenation via expansion multiple times with some tokens protected?

In the MWE below, I want to create a \doPlotCoords macro from scratch, by appending \addplot commands: \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepackage{adjustbox} ...
4
votes
2answers
145 views

Macro for removing whitespace from the start of a string

I want a macro that somehow replaces whitespace (spaces, newlines, tabs?) from the start of a string. Something like mystring.replace(/^\s*/g, "") in JavaScript. Is that possible?
2
votes
0answers
56 views

Passing an array type argument for new command

I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following: \newcommand{\loopy}[1]{ \begin{tikzpicture} \foreach ...
5
votes
3answers
74 views

Define a \newcommand to incorporate colors in \myvariables

I use LaTeX to write my job applications. Since I have more than 50 places to apply for, I like to define variables, such as: \targetorg, \website, \mysignature etc. Since these are sensitive portions ...
4
votes
2answers
67 views

Usage of macros inside \mintinline

I tried to use a macro inside \mintinline. This is the result: \documentclass{article} \newcommand\ab{expanded stuff} \usepackage{minted} \begin{document} ...
4
votes
2answers
74 views

Generate file write handles on the fly

I am experimenting a little bit with automatic generation of file handles via \newwrite. I want to achieve following behaviour: A user provides a list of file categories, for example Hints, ...
1
vote
1answer
26 views

Biblatex create a \citejournal command with journaltitle, date, title

Hello latex community! I'm trying to set a specific command to cite journal articles which doesn't show the author but the journal title, the date and then the article title. I've found this answer: ...
4
votes
3answers
149 views

Build table elements using a macro

1. Small example Consider the following two tables: \documentclass{article} \usepackage{multirow} \usepackage{hyperref} \begin{document} \begin{tabular}{c | c c | c} \multirow{4}{*}{First} & ...
3
votes
2answers
598 views

Why is this parenthesis of a difference size?

I have the following LaTeX: \documentclass{article} \begin{document} \newcommand{\lit}[1]{{\texttt #1}} \lit{()} \lit{(hello)} \lit{(}\lit{)} \lit{hello} \end{document} which produces the ...
5
votes
2answers
67 views

How to make a wrapper for \input

I would like to make a wrapper for \input to include TikZ figures. I have tried something like this: \newcommand{\inputtikz}[1]{% \tikzsetnextfilename{#1} \input{figures/{#1}.tikz} } but with this ...
11
votes
3answers
280 views

How can I break a macro / how to realize a switch or array-structure

I'm looking for a way to realize a macro with a switch/case control structure (or an array solution), as it exists in every programming language. MWE: \documentclass[ngerman,12pt]{article} ...
5
votes
2answers
82 views

Keyvalue argument and non key argument conflict

Many classes provide \part, \chapter, \section and even more deeply nested sectioning levels. All of them allow three forms of usage (I restrict for sake of simplicity to \section, it just stands ...
2
votes
2answers
70 views

Is it possible to pagebreak a longtable if the next “n” amount of rows won't fit on page?

I want to produce a longtable where some "elements" consist of multiple rows (see picture). I want the longtable to pagebreak if the next element doesn't fit in the table. Is there a way to tell ...
9
votes
1answer
141 views

Acceptable use cases for xspace; When will it fail?

I have used xspace for a long time to take care of adding space after usage of some macros. Usually, it is with a macro to format a word consistently, as in: \documentclass[]{article} ...
1
vote
1answer
61 views

Next Sibling Operator

I'm very new to TeX, so I'm not exactly sure what the right terminology is for what I'm asking, so please bear with me! I have a bunch of LaTeX books that I'm converting to HTML via HeVeA. In the TeX ...
12
votes
2answers
271 views

diagonal text in math mode w/ vertical equality

The goal is a code where one can label elements in math mode in the following way: without having to manually position each letter of each word as a node in tikz. Preferably, other than the stacks ...
2
votes
1answer
40 views

Add macro to \chapter command

I am using the report class. And all I want that after the use of \chapter{...} the marco \thispagestyle{onlypagenumber} is added. I fixed this with just defining a new macro \Chapter{...} ...
1
vote
1answer
79 views

Dame latex macros

I am in the initial stages of writing my thesis (Maths). I once wrote a joint paper with someone and because they had an existing template we used it, with all the latex macros it had. Basically ...
8
votes
2answers
301 views

How to replace “E” by “\mathbb{E}” throughout out the article in LaTeX

I have a quick question about replacement in LaTeX. At first, I used capital E throughout my paper and now I really need to replace E by \mathbb{E}, somebody suggests that I can use Macros to achieve. ...
5
votes
3answers
130 views

\newcommand for tabular entries using keyval

I am trying to define a command for tabular entries using keyval. \documentclass{article} \usepackage{keyval} \makeatletter \define@key{tabularEntryKeys}{a}[\dots]{#1 & } ...
7
votes
2answers
165 views

How to decompose a number

I'd like to define a command (namely \myproduct) with two arguments so that when I call it as \myproduct{125}{497} for example, the result would be 3 new commands for each argument, like this: \ci=1 ...
7
votes
2answers
151 views

How to compare against a constant with ifx?

I am trying to test one char substrings (TeX or LaTeX): \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{fp,stringstrings} \newcommand*{\mytest}[1]{% ...
6
votes
2answers
120 views

Arguments to function not losing braces

This MWE is boiled down so much the usefulness of the code is lost. However, the code nevertheless still exhibits the problem I'm encountering. \documentclass{article} \usepackage{pgffor} ...
5
votes
1answer
58 views

Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX? ...
5
votes
3answers
156 views

Incomplete \ifx

I am trying to define a function Lettrine from the lettrine one. I did it here successfully, but I need to add an optional argument to be able to use more lettrine features like ante: ...
3
votes
2answers
98 views

Why does Latex output a quadruple instead of a triple?

To keep track of definitions in a paper, I've written two versions for some macros. One is just the macro, like \mymacro and the other is an unfolded version of the macro, which I usually call ...
6
votes
2answers
55 views

Custom date format

I am trying to create a fancy date format as shown below: The following is a MWE of what I have so far. For some reason or the other I can't seem to get the right height. ...
13
votes
5answers
602 views

a new command of the form ----------{TEX}----------

Is it possible to create a new command of the form ----------{TEX}----------? For instance, I would like to have something like \nc{TEX} which produces "TEX" in the middle of the line and the rest of ...
5
votes
5answers
156 views

new command with cases?

This has been answered here for text outputs with the use of \IfEqCase from the xstring package. But if I want to use the output as a value to set a parameter in a function, it fails. Here is my MWE: ...