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
1
vote
1answer
17 views

Custom minipage: combine options

Following the answer to another question of mine, which had custom minipage settings for quotes, \documentclass[12pt]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[ ...
2
votes
1answer
57 views

Convert a macro from Latex2e to expl3

I'm trying to implement a \Scontents command inside a small package that behaves in two different ways: \Scontents*[opt]<del>argument<del> \Scontents[opt] { argument } With the star it ...
0
votes
1answer
35 views

newcommand counter expansion problem

I am trying to write a macro to support producing a sequence of storyboards for an appendix in a two column IEEE paper. Can the value of a counter be expanded immediately for a macro? Currently the ...
152
votes
5answers
34k views

What exactly do \csname and \endcsname do?

What exactly do \csname and \endcsname do? What are their job? I have glanced at the Texbook and some other books, but none of them was clear enough to me. Can anyone please give a simple example to ...
70
votes
4answers
5k views

What is “expansion”?

I'm relatively new to (La)TeX, but I have a reasonable amount of experience with computational programming languages. Until I began learning (La)TeX, I'd never heard of "expansion"... So, what is "...
0
votes
1answer
15 views

Autosizing for expectation with additional index

I was trying to define a new command for an expectation which scales the vertical dash (in case of conditional expectation) and parenthesis to the argument, respectively. Additionally, I want to have ...
3
votes
1answer
53 views

Mysterious horizontal space when using conditional macro

In order to deal with both burdensome expressions $K$-vector space and $K$-vector space $E$ at once, and this in both text and math mode alike, I defined a fine working shortcut taking two arguments, ...
1
vote
0answers
16 views

TeX4ht: Strange behavior when I include `\xymatrix` in a macro

See the following code: \documentclass{amsart} \usepackage[matrix,arrow,curve,cmtip]{xy} \begin{document} \newcommand\test{ \xymatrix{{a} \ar^-{b}[r] & {c} \ar@<0.7ex>^-{d}[r]\ar@<-0....
0
votes
0answers
10 views

TexStudio autocompletion stopped working for macros

So I recently created macros (.sty files), which are remotely loaded at in my preamble. There are various points in these macros where I've defined a new command; for example: \def\remark#1#{\...
0
votes
2answers
29 views

changing the behavior of a command

if \foo{Complete} compiles to The Status: Complete How can I change my LaTeX code so that \foo{Complete} compiles to Status: Complete This only needs to be changed in one place. I'm having trouble ...
2
votes
1answer
40 views

Change command in package

Im trying to use the venndiagram package but i want to change the colour it fills in the areas. Currently if you use the code for example \begin{venndiagram2sets} \fillOnlyA \fillNotAorB \fillA \end{...
0
votes
0answers
47 views

How to test for existence of a string in a tex file?

How can I obtain a command that tests for existence of a string in a tex file? Example: if ('foo' is in file.tex) then raise error (You used foo, please don't use foo)
0
votes
0answers
23 views

Cannot define a split equation macro [duplicate]

I want to combine the \equation* command and the \split command into a single macro. This is what I want to do: \def\beqn{\begin{equation*} \begin{split}} \def\eeqn{\end{split} \end{equation*}} \...
1
vote
1answer
41 views

adaptive math newcommand for indices

I have defined a command to add a star as the power to the input variable. It has to be in an adaptive way that if the input has indices, star is added to the main parameter and not the whole input. ...
1
vote
2answers
24 views

Reledmac: Customize familiar notes mark

I would like to make a the footnote mark smaller, and, in the familiar footnotes, distance the text from the mark. I have tried the \thefootnoteA macro (reledmac manual 6.5.2), but I don't know how to ...
2
votes
1answer
44 views

How to avoid defining something inside of a macro that uses '\csname \endcsname'?

The following code gives no error and works fine: \documentclass{memoir} \def\ThingyFred {This is the thingy named Fred} \begin{document} \chapter{Fred} \ThingyFred \end{document} And the ...
0
votes
0answers
25 views

Spacing issue with the newcommand [duplicate]

I had created an abbreviation (abv) shortcut using the newcommand. However the command did not render as expected. Specifically, there is a gap between the abv and punctuation marks (See line 1 of the ...
0
votes
0answers
31 views

Redefining `\global\long\def` to always use `\robustify`

I use LyX and the math macros are compiled to LaTeX using \global\long\def\mymacro#1#2{body} (for a binary macro). This leads to me having to \robustify many of those macros. I tried redefining \def ...
2
votes
1answer
39 views

Restricting commands

I have a class file that is used by my students to create their final year project reports. The class imposes a style and limits the number of pages the students can write. However, there is nothing ...
1
vote
1answer
20 views

Render/Preview Commands Stored in External File in LyX

I would like a file of latex commands to be rendered in LyX's editor. Variations of this question exist all over the internet and tex stack exchange, but the answers seem either inconsistent, not ...
0
votes
1answer
51 views

writing functions and wrapping commands for abstraction

Can i write a little function (or macro or whatever) that wraps two commands (functions?) into one; united under a single alias? Specifically I want to wrap \input{} and \includegraphics{} into a ...
0
votes
2answers
338 views

newcommand for ket-bra

How can create a \newcommand that be able generate: |\phi\rangle\langle \psi| However \ket{\phi}\bra{\psi} does that but we think that the distance between ket and bra in |\phi\rangle\langle \psi| ...
0
votes
2answers
41 views

Macro to format a list with arbitrary items

I'm trying to build a macro that can be used to place an arbitrary number of items in a list Currently my macro looks like this \newcommand\presentation[6]{ \begin{minipage}[t]{\dimexpr(\...
1
vote
1answer
61 views

\newcommand with many arguments

I'm trying to build a command that displays a sort of checklist. Ideally, I only want to pass a set of boolean values to that command. A naive MWE looks like this: \documentclass{article} \...
0
votes
1answer
53 views

Shrinking padding of node with label options

I am trying to implement command — let's name it fn — aimed to behave like overset command and underline the lower word with some curve. Doing this using TikZ. The lower word is made as node text, and ...
1
vote
0answers
36 views

Dynamically Building Table of Referenced Documents

I have a document that's going to reference other documents. For now, I have placed placeholders to the usage throughout my document as follows: ... blah blah \docReferenceMeaningfulNameHere blah ...
4
votes
3answers
25k views

\bold in math environment

Having forgotten the command to make text bold in math mode I naively tried $\bold{bold var goes here} these maths symbols are not bold$ and it worked! I became immediately suspicious as I know ...
5
votes
2answers
152 views

Conditionally replacing sequences of characters

I am a noob in the area of plain TeX. All commands which are used in this question are written with the help of answers on this site and the 'LaTeX Wikibook'. I want to change keyboard mapping using ...
69
votes
4answers
8k views

Why do LaTeX internal commands have an @ in them?

Does the @ mean anything specific? For example, is it substituted? Does it split the command into parts, like \s@foo could internally mean "foo of type s"? Is the purpose of the @ only to make ...
75
votes
1answer
2k views

A LaTeX log analyzer application (visualizing TeX expansion)

This question led to a new package: unravel Consider the following MWE, test.tex: \documentclass[12pt]{article} \begin{document} \tracingassigns=1 \tracingmacros=1 \def\aaa{something} \def\bbb{...
2
votes
1answer
33 views

Large space appearing before my newcommand

I've created this code which hopefully will make glossing a lot easier, the first input decides the order of a Transcription, Phonemic reading, Phonetic reading, and Gloss, and uses the input to ...
1
vote
1answer
67 views

How to force RefTeX to parse the document for a specific word

One of the book which I am translating is using "Ruby" macros and Ruby makes all pre-processing for LaTeX. For Example, there is a command inside the document such as: <% fig("soccer-ball") %> ...
4
votes
3answers
72 views

Add material to a macro with parameter

I'm trying to define a macro \addtohook that adds material to another macro \hook, similar to LaTeX's \addto@hook, but where \hook takes a parameter. So if \hook is empty at start, after a series of \...
2
votes
1answer
64 views

Macro to switch bold on and off in table cells

I have start looking at the package cals, so my examples are connected to that packages. However, my questions are general, applicable under other environments, too. In the documentation (this ...
1
vote
1answer
336 views

Create a fake “\meaning” (verbatimized) for content stored in seq?

I'm trying to create a command that represents the code that is stored in a sequence without executing it (something like \meaning) . When using \cs_log:N \l_scontents_macro_tmp_tl I get in the .log ...
0
votes
0answers
45 views

Underscore Usage in Xparse

This is a macro for producing vector length symbols. The mandatory argument m receives vector notations, which the optional argument o receives whatever should be added as subscripts if they are ...
0
votes
0answers
29 views

Commands to export latex file [duplicate]

I would like to create a trigger to export Latex file on the tool bar to replace Update trigger. Anyone knows the commands behind this Export>LaTeX(XeTeX)?Or where could I find the command? Thanks in ...
2
votes
2answers
66 views

How do I define and use macros that define macros?

I am new to TeX and LaTeX, and I am having trouble defining and using macros that define other macros. I've read about how to do so (for example, https://en.wikibooks.org/wiki/LaTeX/Plain_TeX#...
0
votes
1answer
44 views

Custom commands with optional arguments in section title

There are many instances where I need to create my own commands and a lot of the time I also need them to have an optional argument. No problems there. However, I needed to have one of my commands ...
1
vote
1answer
45 views

Evaluation problem with the label/reference mechanism

I am defining a computation environment which defines a bunch of equations. Each equation has a number and I want to print that number. To generate automatically the correct number, I use the label/...
1
vote
2answers
73 views

Macro that takes a variable number of arguments, and creates a table with one row per argument

I am trying to create a macro that takes a variable number of arguments and creates a table where each argument becomes one row; so assuming the command is called dynamictable, calling it like this \...
28
votes
5answers
18k views

\vec{x} but with arrow from right to left?

I have two variables: \vec{x} and another one which is somehow dual to the first. Therefore I would like to symbolize the second with something similar but a leftarrow on top of the x. I already tried ...
19
votes
2answers
2k views

Are all commands with an optional argument fragile?

Here is a discussion of fragile command in LaTeX. And it says that any commands that have an optional argument are fragile, for instance \footnote[2]{myfoottext} and \footnot{myotherfoottext}. I have ...
6
votes
3answers
220 views

Inserting full stops between letters with a macro

I was thinking recently that it would be really useful to have a macro that would fill in full stops between the letters of an acronym, say \acr which would take an input \acr{WHO} and spit out ‘W.H.O....
1
vote
1answer
34 views

Custom minipage command for quotes

\documentclass[12pt]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[ paperwidth=32pc,% paperheight=48pc,% margin=4pc,% ]{geometry} \begin{document} \begin{...
6
votes
1answer
279 views

starred version of DeclareRobustCommand

I generally use \newcommand* instead \newcommand whenever it makes sense, to ease error checking if the command doesn't sensibly take multi-paragraph arguments. Is there a starred version of \...
1
vote
2answers
23 views

Is it possible to auto infer macros which have a common prefix?

Let say that I have the following code: \documentclass{article} \usepackage{xspace} \def\cal#1{\ensuremath{\mathcal{#1}}\xspace} \newcommand{\calA}{\cal A} \begin{document} Let \calA be a ...
2
votes
0answers
76 views

How do use {<setup>} in \tl_set_rescan:Nnn to replace \scantokens?

This question is related to (Changing escape character in \tl_set_rescan:Nnn) and (https://tex.stackexchange.com/a/496258/7832) but is not the same. I've tried to change this: \exp_args:NNx \...
0
votes
4answers
119 views

Environment for a cheatsheet table

I would like to create a new environment to create small tables to use in a cheatsheet. I want it to look pretty much like this and would like to invoke it with something like: \begin{commandtable}...
1
vote
1answer
40 views

Expanding a command when assigning values to an array

I'll explain what I mean with an example. \documentclass{article} \usepackage{arrayjobx} \newcounter{foo} \setcounter{foo}{0} \renewcommand{\bar}{\addtocounter{foo}{1}Some text} \newarray\baz % ------...