2022 Developer Survey is open! Take survey.

Questions tagged [macros]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
35 views

Create macro with variable number of comma separated arguments in plain TeX?

I wish to create two macros: one that takes a known number, and another that takes an unknown number of arguments that are comma-separated and does something with them. There have been a few answers ...
user avatar
  • 307
1 vote
1 answer
33 views

Automate how the author appears in the text

I have a problem with LaTex and the style guide of the ISMAR papers. They state that: when citing references, do not use the reference as a sentence object; e. g., wrong: “In [4] the authors describe ...
user avatar
-1 votes
0 answers
33 views

Animated code maybe not using it properly

I have found this code below from @Qrrbrbirlbel form making an animated thermometer: \documentclass[tikz,convert=false]{standalone} \usepackage{fourier,siunitx} 0 \definecolor{coldblue}{cmyk}{0.321 0....
user avatar
  • 25
2 votes
3 answers
74 views

Count the number of a given character in a token list and apply the corresponding operation

I would like to define a command that counts the number of a substring in the input and apply corresponding operation according to the result. For example, in the following code, the command should ...
user avatar
  • 5,074
4 votes
3 answers
117 views

Can't multiply width in \newcommand for includegraphics

Minimal example, multiplying by 0.5 makes the command fail : \documentclass{beamer} \usepackage{graphicx} \begin{document} \newcommand{\dontwork}[1]{\includegraphics[width=0.5*(#1)\textwidth]{frog.jpg}...
user avatar
  • 149
0 votes
1 answer
59 views

How can I define this new math mode environment with comma-separated keyval options?

My MWE using LuaLaTeX: \documentclass[oneside,DIV=12]{scrbook} \usepackage{scrhack} \usepackage[automark]{scrlayer-scrpage} \usepackage[english]{babel} \usepackage[babel]{microtype} \usepackage{...
user avatar
1 vote
0 answers
27 views

Is whitespace allowed between \section and \index or \label?

Sometimes I need to add a label or index immediately after a new chapter/section/subsection, etc., and the code may look like: \section{TITLE} \index{INDEX} \label{LABEL} This works fine in my ...
user avatar
  • 5,074
0 votes
0 answers
13 views

How to make text at center of column in a table for CV

I have started writing a CV in latex. I have taken a template from Overleaf and started modifying it. I want the title in CV as follows: I have tried the following code: \newcommand*{\setname}[2]{\...
user avatar
6 votes
3 answers
392 views

How to use \catcode in a command?

I would like to define the character @ as follows: \def @#1#2{\catcode`#1=13\def #1{#2}} so that when I type @xy x, TeX typesets y. However, when I run this, I get an error. I have seen other answers ...
user avatar
  • 307
0 votes
2 answers
38 views

Align text // newcommand

I am using the following code, but can't figure out how to align the paragraph to the left. Can someone help me, please? \documentclass{scrartcl} \reversemarginpar % Move the margin to the left of ...
user avatar
2 votes
0 answers
34 views

How to define a command like `\node` of `tikz` package

With tikz, we can write \documentclass{article} \usepackage{tikz} \tikzstyle{mystyle} = [rectangle, text centered] \begin{document} \begin{tikzpicture} \node [mystyle] at (0, 0) (mylabel)...
user avatar
1 vote
1 answer
31 views

How can I align tikz nodes ragged left?

I'm producing a CV from a template which uses tikz nodes for a general skills section. This is what the section looks like: I would like the nodes to be left-aligned in relation to one another, ...
user avatar
  • 133
0 votes
1 answer
68 views

Pass tabular arguments from \newcommand

So I asked this question yesterday but I realized I didn't do a good job of explaining it. I basically need to read different csv files with different numbers of columns and I need to build a command ...
user avatar
1 vote
0 answers
56 views

How to create an array of colors? [closed]

I am trying to pass an array of colors (of any length) into a macro command to then be used when filling the background of tikz shapes. I've been successful, however, I ran into an issue with the none ...
user avatar
2 votes
2 answers
124 views

LaTeX macro for complexity theory problem statement

I'm writing a thesis where I define some computational problems and I want them all to have the usual style presented in textbooks. Something like this: I defined a command to do this easily as a ...
user avatar
1 vote
0 answers
52 views

Detect \end of an environment

I'm trying to create a macro that grabs everything till the end of the current environment and parses it. At first, I just want to put ! right after my macro and another one ! before the end of ...
user avatar
  • 1,775
0 votes
0 answers
29 views

How to write the output in multiple pdf files [duplicate]

Suppose that I want to split the output of my LaTeX document in several .pdf files. Is there something like: \fromnowwritetofile{foo.pdf} some part of my document \fromnowritetofile{foo2.pdf} some ...
user avatar
0 votes
1 answer
35 views

Meaning of square brackets, optional arguments

I'm a bit confused as to how LaTeX parses square brackets/optional macro arguments. I'll try to explain what I understood by means of the macro \section which has one optional and one mandatory ...
user avatar
3 votes
2 answers
67 views

Can xparse distinguish arguments inside braces and single-token arguments without braces?

The \foreach command from pgffor package has a good feature that it can distinguish arguments inside braces and single-token arguments without braces: \foreach \i in {1,2,3} {do some thing} \def\...
user avatar
  • 7,886
1 vote
1 answer
40 views

problem with spaces and getitems package

When gathering items, I would like to avoid inital and final blank lines and spaces. I explain with an example. Here my code \documentclass{article} \usepackage{getitems} \NewEnviron{test}{ \...
user avatar
0 votes
1 answer
63 views

Why doesn't the new command work? [closed]

\documentclass[12pt]{article} \usepackage[T1]{fontenc} \newcommand*{\QEDA}{\null\nobreak\hfill\ensuremath{\blacksquare}} \begin{document} test \QEDA \end{document} The error says "undefined ...
user avatar
  • 91
7 votes
3 answers
415 views

How to write a command that includes a figure?

I would like a shorthand command to include a figure. Description and filename are mandatory Short caption is optional Optional arguments can be passed to \includegraphics Here's the snippet I am ...
user avatar
  • 1,059
1 vote
1 answer
19 views

Help with newenvironment for unnumbered theorems

First I tried this \newenvironment{axioma}[2]{\newtheorem*{#1}{#2} \begin{#1}}{\end{#1}}. It did not work. Then I tried \newenvironment{axioma}[1]{\newcommand{\axiomhead}{\newtheorem*{kkk}{#1}} \...
user avatar
0 votes
2 answers
125 views

How to remove any kind of spaces at the beginning of something

This is another chapter of the story "how to use a moodle database for my purposes". The accepted answer to this question gives a very effective way to retrieve informations from an exercise ...
user avatar
1 vote
1 answer
42 views

Find the first character of a string (problem with blank lines)

I'm trying to build a macro that gives the first character of a argument the code \def\FIRST#1{\First#1\TAIL} \def\First#1#2\TAIL{#1} works almost fine: \FIRST{WORD} produces W as expected, but \...
user avatar
0 votes
2 answers
96 views

How to check that something starts with * (or how to build your own exercise sheet from a moodle database)

I would like to check if something starts with an asterisk (*) My attempt: \def\testast#1{\ifx*#1\relax YES\else NO\fi} But the output of \testast{*Word} is WordYES while I would expect just YES The ...
user avatar
7 votes
2 answers
164 views

When does tex do macro expansion?

Having read some chapters of the texbook, I know tex eats input lines from command line or files, then converts them into tokens. When these tokens go into its gastro-intestinal tract, tex prepares to ...
user avatar
  • 2,609
1 vote
1 answer
46 views

How to parse an itemized list the way moodle.sty does

A simple moodle.sty database contains code like that: \begin{multi}{Name of the question} Text of the question \item first answer \item secon answer \item* the starred is the ...
user avatar
0 votes
0 answers
17 views

New environment gives "File ended while scanning use of \thmt@collect@body."

In the code below, I use starred theorems through some macros and commands. \documentclass[]{article} \usepackage[english]{babel} \usepackage{amssymb,amsthm,amsmath,xparse} \usepackage{hyperref} \...
user avatar
1 vote
1 answer
35 views

How to Push a Secondarily Defined Lettrine Out of the Margin of the Page

I am working on a document in which I would like to incorporate a secondary lettrine outside of the one which is mainly used. Consider the code \documentclass{book} \usepackage{fontspec} \usepackage{...
user avatar
  • 4,969
2 votes
2 answers
60 views

How to gobble a character, if present

I would like to do the folloging: Given a (complicated) string/macro \String, if it starts with * I just remove it, otherwise I do nothing. So far I tryed \def\gobbleast *{}% then \gobbleast \String ...
user avatar
0 votes
2 answers
35 views

Hide new command contents

I am adding comments to my latex using newly defined commands like this: \newcommand{\mycomment}[3]{\textcolor{#1}{\small [#2: #3]}} \newcommand{\reviewerA}[1]{\mycomment{blue}{Reviewer 1:}{#1}} %... \...
user avatar
  • 101
2 votes
2 answers
224 views

Defining a new command, the output of which depends on an internal parameter

Maybe someone can tell me how to define a new command in \LaTeX, which can take one mandatory value and another optional value (parameter) as input. In this case, depending on the value of the ...
user avatar
  • 97
0 votes
0 answers
32 views

Printing command in latex [duplicate]

I have installed new package which has a command "\mysteryCommand". It doesn't quite do what I'm looking for. How do I dump this command's actual text? I can find documentation and help me ...
user avatar
2 votes
2 answers
60 views

Commands break when processing token by token

I'm trying to make a command that goes in \everymath which formats certain specified characters (automatically puts v in \mathbf, etc.). That part I've actually already figured out, but what's giving ...
user avatar
0 votes
1 answer
30 views

How to check that the double expansion of something is empty?

I'm using the listofitems package, which produce a list whose elements are accessable by \LIST[n] but in the manual I read that I need a double expansion. In particular how do I chek that (the double ...
user avatar
2 votes
2 answers
53 views

Generate command definitions that take arguments

I want to define a command \NewSmartOp such that: \NewSmartOp \MYOP \myop would produce the following code (or anything equivalent): \makeatletter \def\MYOP{\@ifstar\MYOP@star\MYOP@nostar} \def\...
user avatar
  • 216
0 votes
2 answers
57 views

Define a command where the name has a suffix

Say I define the command \newcommand{\d}[1]{\mathrm{d}#1}. I can use it like \d{x} or \d{y}. Is it possible to define the command \d, such that I can use it like \dx or \dy without an argument?
user avatar
  • 175
1 vote
1 answer
32 views

How do I use foreach in a tikzpicture environment with a macro input?

I am drawing a picture in my document using a foreach loop in a tikzpicture environment, like this stripped-down example: \documentclass{standalone} \usepackage{tikz} \newcommand{\drawBoxes}[1]{ \...
user avatar
0 votes
1 answer
35 views

Ignore command invocation in `ifnum` argument

I have a command \yesifone that should take either 1 or 0 as an argument, and behaves differently depending on these two cases. I want to pass to it the output of a command \one. However, \one relies ...
user avatar
  • 413
0 votes
0 answers
31 views

How to define *and* redefine in class file?

I'm creating a resume and have create my own custom resume class (doesn't everybody?). I have multiple positions that I want to typeset so I have something like this: \documentclass{mcv} \begin{...
user avatar
  • 9,492
2 votes
2 answers
41 views

Double colon in prettyref label

The prettyref package works by inspecting labels of the form \label{format:name} and creating a reference based on just the format:. The documentation says: Do not use the character : anywhere within ...
user avatar
  • 273
1 vote
1 answer
27 views

\pdfstringdefDisableCommands with starred and non starred commands

The following MCE: \documentclass{article} \usepackage{hyperref} \ExplSyntaxOn \NewDocumentCommand { \foo } { s m } { \IfBooleanTF {#1}{ Foo~ #2 }{ #2 } } \pdfstringdefDisableCommands{ ...
user avatar
2 votes
2 answers
199 views

Is there a way to automatically smash all inline maths (but only vertically)?

What it says on the tin. In case it isn't clear enough, what I would like is for $...$ to be typeset as \smash{$...$}, except \smash also affects horizontal spacing (see the question I linked to below)...
user avatar
  • 182
0 votes
0 answers
212 views

a verb=xxx_== problem with newcommand - missing $ inserted

\documentclass[12pt,a4paper,UTF8, scheme = plain]{ctexrep} \usepackage{amsmath,enumerate} \usepackage{geometry} \usepackage{adjustbox} \usepackage{booktabs} \usepackage{fancyhdr} \usepackage{lastpage} ...
user avatar
  • 489
0 votes
1 answer
29 views

Passing string containing "special" catcodes (especially `_`) to custom NewDocumentCommand command

How can I pass underscore to \newcommand properly? suggests the solution is to use a zero-argument command that changes the catcode of _, before expanding to the actual command. That's kind of the ...
user avatar
4 votes
2 answers
226 views

Why is there no \ProvideCommandCopy?

When we look at xparse package documentation there are four related commands \NewDocumentCommand \RenewDocumentCommand \ProvideDocumentCommand \DeclareDocumentCommand Similarly there are four ...
user avatar
  • 145
1 vote
3 answers
35 views

Custom new command in math mode with two alternative outputs depending on input arguments

I have written some custom commands to use inside mathmode. The command basically corrects the style of the left side sub and superscript. It decides which script is the longest and right-justify the ...
user avatar
  • 640
0 votes
2 answers
104 views

How to produce suitable spaces surround the differential symbol d in dx?

I'm creating a list with common math commands that I use, but \newcommand and \DeclareMathOperator both add a space after the symbol I just defined. For example, comparing the two commands defined ...
user avatar
0 votes
1 answer
25 views

"No lines to end" issue with itemize inside a macro

\newcounter{question}[section] \setlength{\parindent}{24pt} \newcommand{\question}[2]{\noindent\textbf{\thesubsection(\thequestion)} -- \textsl{#1}\\[0.2cm]}\indent#2\stepcounter{question}} I wrote ...
user avatar
  • 163

1
2 3 4 5
151