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

4
votes
2answers
47 views

How can I know the number of expandafters when appending to a csname macro?

I am looking for an informative answer here. If I want to append to a macro, I have a couple of options, each depending on whether I want the items fully expanded, partially expanded (a certain number ...
3
votes
0answers
68 views

Rewriting an environment (or command) using xparse for expand argument

I'm trying to write the documentation for script which I am working on using the packageltxdoc and docstrip. I have defined several commands using the package xparse and I would like to define a new ...
2
votes
1answer
48 views

White space with subfigures using a macro

EDIT The answer proposed by egreg doesn't work for me: When changing the outer sep to outer sep=-10pt, instead of shifting the images, just the labels get shifted and the white space persists. ...
12
votes
2answers
212 views
+500

Xparse k argument to parse options at end of environment

I am trying to combine the solutions from How to properly use \collect@body within align environment Xparse t argument type (underscore with optional parameter) to parse optional parameters ...
3
votes
2answers
35 views

Trying to understand how \@cdr…\@nil works in relation to \expandafter

I am trying to define a macro \@ifnextchars with three arguments, the first argument being a list of characters, which expands to either the second or the third argument depending on whether one of ...
4
votes
1answer
30 views

How can I make a command execute exactly once in an AMS environment?

I'm wanting to create a command similar to AMS's proof environment that automatically calls a command (like AMS's \qedhere) when it gets to the end, but allows you to call the command earlier if you ...
9
votes
3answers
439 views

Print only Unique numbers

Have list of numbers captured through the command \Numbers. When using \PrintNumbers, it should print only the unique numbers. MWE: \documentclass{article} \makeatletter \gdef\PrintNumbers{} \def\...
1
vote
0answers
58 views

Is there a perfect set of macros for typesetting? [on hold]

I understand using tex (primitives) you can get 99.9% control over how a document is typeset. Macros are simply a way to make this more efficient, and easier for non-technical users. I read that latex ...
1
vote
1answer
29 views

Border height not consistent in tikzpicture

I defined a new command to divide a rectangle in three parts, each containing a title. However, the middle part is somehow. Can someone please explain me why this is the case? \newcommand{\...
3
votes
1answer
35 views

How can I make a command execute exactly once in an argument?

I'm wanting to create a command similar to AMS's proof environment that automatically calls a command (like AMS's \qedhere) when it gets to the end, but allows you to call the command earlier if you ...
1
vote
1answer
54 views

Remarks using Changes Package

Using the changes package, how can I create a 'remark', which is displayed in the same markup colour formatting, and included in the list of changes when in draft or normal mode, but is removed ...
5
votes
2answers
45 views

How to expand a macro in a superscript without curly braces?

Suppose we have \newcommand{\inv}{-1} We want to be able to do $A^\inv$ instead of $A^{\inv}$ but that won't work — only the minus sign is superscripted. Accidentally I stumbled on a possible ...
1
vote
0answers
32 views

How to create command that associates pieces of content to keep them on same page?

I've pieced together a class for my preferred format of Cornell notes, and it allows for floating a summary to the bottom of a page. But, it requires manually choosing the page that will host the ...
1
vote
2answers
47 views

Best way to create custom number of table rows

Is there any standard way of defining a class so that \startTable \newTableEntry{x}{12.1} \newTableEntry{y}{11.1} \endTable can be done? The result should be x 12.1 y 11.1 Thanks!
2
votes
1answer
19 views

Pass iteration variable from foreach to custom command

I am trying to figure out why the following code does not work: \documentclass{article} \usepackage{etoolbox} \usepackage{pgffor} \newcommand\setProblemShow[2]{% \csdef{isProblemShow#1}{#2}} \...
0
votes
0answers
42 views

Add and position the command \photo to a mix of moderncv styles

This is a follow-up question to Banking style of moderncv doesnt reconize `\makecvheadnamewidth` for fiting long names and to How to mix/combine moderncv styles?. Now I am looking to add the ...
1
vote
1answer
40 views

Newcommand not working in Lyx

I am using lyx for writing a latex document. The following is the preamble in Document > Settings: \usepackage{fullpage} \newcommand{\authnote}[1]{\textcolor{green}{\small {\textbf{(Auth:} #1\...
0
votes
1answer
30 views

Finding out the number of needed macro arguments

How can I find out how many arguments (i.e. {} pairs) are used when 'calling' a macro? (my favorite error, that I extend a macro, i.e. it needs one more argument, then I use it to compile a text ...
1
vote
2answers
66 views

Highest Variable Value on Every Page

I am writing a document where each paragraph is categorized. I'm encoding the category as a simple numeric variable: 1, 2, 3, &c. On each page I want to know and possibly display the highest ...
10
votes
2answers
137 views

Creating an error message

Is there a way to create my own error message that is given if the main font size isn't set to 11pt and then the compilation of the document begin stopped? Update I'm trying to write a package, ...
3
votes
2answers
47 views

Get title of current section of a specific level (similar to \thesection)

Similar to thesection, thesubsection, ... I want to obtain the title of a section (as it is in the body of the document), via for example (pseudo-code) \thesectiontitle, \thesubsectiontitle, ... The ...
2
votes
1answer
52 views

How to test if a label exists

I have tried to follow another question but I cannot get it to work. My question is: How do print a text based on if a reference exists or not? I have tried the following: \usepackage{etoolbox} \...
2
votes
1answer
24 views

Automatically align edge labels left or right in forest

I was trying to get edge labels to automatically appear to the left or the right of edges, depending on whether the corresponding node in the tree was a left or a right daughter. When I insert the ...
5
votes
3answers
74 views

Xparse t argument type (underscore with optional parameter)

I am not understanding how to use the t type parameter with xparse's \NewDocumentCommand. I am trying to define a macro that accepts one optional parameter, but the optional parameter is specified ...
2
votes
1answer
58 views

Using an undefined token as argument

I have a (probably) quite uncommon problem. Pseudocode: \def\head{\titel } % \titel = undefined \func{\head} % func is defined and handles \titel without any issues \func{\titel} % throws an ...
2
votes
1answer
161 views

Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry

If I want to conditionally expand a glossary entry based on or related to another glossary term, I find the conditional \ifglsused{}{}{} statement is very helpful. To satisfy parent modifications ...
1
vote
0answers
14 views

Automatic new line to my macro [duplicate]

I've created that new macro: \newcommand{\undbf}[1] {\textbf{\underline{\smash{#1}}}} To get underline closer to letters but, for instance with this code: \documentclass[8pt,a4paper,dvipsnames]{...
4
votes
2answers
407 views

Redefine _ like _{\!_{ }}

I would like redefine _ like _{\!_{ }} to do subscripts smaller. I've tried with: \renewcommand{\_}[1] {_{\!_{#1}}} But it doesn't work, apparently, maybe I'm wrong. Take this equation, for ...
0
votes
1answer
19 views

Redefine \psq and \psqq to refrain from inserting a space after page number

The Biblatex manual tells me about the \psq-command: "The spacing inserted between the suffix and the page number may be modified by redefining the macro \sqspace. The default is an unbreakable ...
2
votes
2answers
75 views

How can I loop through macros with \foreach and pass them to \xapptocmd?

Can I use pgffor to loop through macros (control sequences)? e.g. \foreach \macro in {\lions,\tigers,\bears} In case you haven't figured it out, I love modularization! Let's say I have three ...
1
vote
1answer
24 views

xparse error: “kernel/missing-colon” when defining a new command using cs_new:Nn

I'll simply show what happens: The documentclass definition is elsewhere on the file. I'm using TeXnicCenter, so interactive mode is not an option.
0
votes
0answers
19 views

Manual removal of trailing spaces from macros [duplicate]

Suppose I'm defining a macro of some word I'm using a lot: \providecommand{\pv}{\emph{p-valor }} I already put the trailing space because most of the time it'll save from adding it manually (yes, I ...
0
votes
0answers
25 views

“parameterize” newcommand to avoid repetition [duplicate]

Say I want to use the scripts letters in my document. For every script letter, I want to make the command to write that script letter shorter. That is, I want to write \newcommand{\sA}{\mathscr{A}} \...
13
votes
7answers
567 views

Extract first letter of each word, also after a special character like a dash

This question based on this answer. Found letter missing when it occurs next to dash, as per the below MWE: \documentclass{article} \usepackage{readarray} \usepackage{ifthen} \newcounter{index}\...
3
votes
0answers
45 views

Difference between tableofcontents and listoffigures internal codes

In standard classes book.cls and report.cls we find \newcommand\tableofcontents{% \if@twocolumn \@restonecoltrue\onecolumn \else \@restonecolfalse \fi \chapter*{\...
2
votes
3answers
125 views

Derivatives conditional typesetting command?

I want to make a command to simplify my equations typesetting. I have many equations including high order derivative \frac{\partial^2y}{\partial x^2} \frac{\partial^3z}{\partial t^3} .... Now I ...
1
vote
2answers
56 views

How to define a href-like command?

I'm trying to make an \href-like command that will color its text. The one I made breaks when the URL has #. I tried the solution in here, but it still doesn't work. \documentclass{article} \...
6
votes
2answers
45 views

How do I set a formula in bold-face except for certain commands?

I am trying to typeset a sparse matrix: \documentclass{article} \usepackage{amsmath} \newcommand{\z}{0} % Zero entry \begin{document} $$ \begin{pmatrix} \dot{\mathit{vx}} & \dot{\mathit{vy}} &...
1
vote
2answers
65 views

How can I pass expanded material to a macro at definition time (context-specific macro tracker)?

Expansion gives me headaches. I could use some help. The problem is identified under the heading: Log Output Snippet AtEndAfterFileList. This is an extension of my context-based log entry question: ...
3
votes
3answers
88 views

Count Lines in a Block of Text

I would like to have a macro that counts the number of lines in a block of text. I was able to create one based on the answer for "counting the newlines in title", but I would prefer that the macro ...
4
votes
0answers
25 views

LyX functions: Nest label from clipboard into inset insert

In writing my thesis in LyX I make frequent use of the label-copy-as-reference function - mainly from equations but also with other labels. The labels are however not pasted as formatted reference ...
13
votes
4answers
359 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
0answers
61 views

Best practices for “factoring” relatively small snippets of shared code

My particular use case is that I have a long academic CV, and a short résumé. The two of them share a reasonable amount of textual content, but, for example, the order of the content varies, some ...
8
votes
1answer
194 views

Have a command acting on the environment body

I need to turn this \begin{FOO} my little pony \end{FOO} into this \bar{my little pony} I have tried this: \newenvironment{FOO}{\bar}{} But this seems to only make \bar apply on the first ...
0
votes
0answers
20 views

Allow automatic line breaks for custom commands [duplicate]

I have created a custom command for links in order to format them in a way I want to: \newcommand{\R}{\normalfont\underline} This works, but if I use this command with long texts and hyperref, ...
0
votes
1answer
29 views

Inline derivative macro

I'm trying to define a macro so that $\D{x^2,y^3}$ expands to $\partial_x^2 \partial_y^3$. I tried \makeatletter \newcommand{\D}[1]{% \@for\@token:={#1}\do{\partial_\@token } } \makeatother ...
2
votes
2answers
84 views

Using a command to append data to another one

I've just wanted to add some elements to an existing command/variable without success. There are many examples for different ways on how to achieve that goal, but none of them seem to work for me. In ...
37
votes
7answers
17k views

What is the recommended way to assign a value to a variable and retrieve it for later use?

What is the recommended way to define a variable inside a document and retrieve its value later? I've googled several different solutions, usually about ~10 lines long. I was wondering, that there ...
5
votes
1answer
103 views

Examples of table of contents in pure TeX

I'd like to try to create a document structure and table of contents in pure TeX. Does anyone know of any resources or examples to do this? My purpose is mainly educational, to learn how to write ...
4
votes
1answer
58 views

Macro- allowframebreaks as default returns error when loaded with fragile

This is a follow-up question to this answer. I noticed that the macro proposed returns error if the frame is loaded with the parameter fragile \begin{frame}[fragile]. Note that when issuing manually ...