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

0
votes
0answers
13 views

Extraction of first letter of every word in a document

How can I extract the first letter of every word in a document and keep all punctuations and capitalization?
1
vote
2answers
17 views

Value of counter from pgffor in a complex example

From this answer I learned how to print rows into 1 column table using pgffor: | 1 | | 2 | | 3 | Code looks like this: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{pgffor} \...
0
votes
1answer
21 views

invoking mathtype from texsudio

Any idea how can I automatically invoke Mathtype from texstudio using macro (javascript) and put the formula back onto texstudio automatically. It can be done manually, but I want to know is it ...
9
votes
2answers
130 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
92 views

Rewriting a command using xparse for common code

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 ...
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
459 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
59 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 ...
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
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 ...
12
votes
2answers
220 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
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
76 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 ...
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
408 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}} \...
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
57 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}} &...
13
votes
7answers
575 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}\...
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: ...
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 ...
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 ...
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 ...
4
votes
1answer
68 views

tcolorbox in margin notes

I'm trying to create a command that will allow me to add little "important notes" on the margin of my document. I have managed to make it work as long as as I use the "left" option for the box and the ...
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 ...
5
votes
1answer
104 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 ...
6
votes
3answers
124 views

New command for automatic enumerate generation

I was thinking about a macro with only one argument, but of varibale length expanding the parameters into an enumeration. E.g.: \dostuff{a} expand to \begin{enumerate} \item a. \end{...
3
votes
1answer
70 views

Generating a table with all entries from all over the document

We're working on a technical document where we define messages in different chapter/section all over the document. All messages have the same structure and are displayed in a table. We thought that it ...
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 ...
3
votes
2answers
91 views

String comparison with list/array of variables

Is it possible to do a string comparison with a list/array of variables? Here is my example code, ticking the defined \currentbox: \documentclass{standalone} \usepackage[most]{tcolorbox} \...
4
votes
2answers
124 views

Create a new command that makes a footnote with a custom prefix

New to macros here, I need to be able to create a document with the regular footnote commands and a custom command that makes footnotes work identically to the regular one but add a prefix ''R'' ...