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
2answers
42 views

Define a command differently in inline vs display mode

I would like to have a command \catlim which behaves differently in inline vs in display mode. Namely, in inline mode, it should be equivalent to \lim and in display mode, it should be equivalent to \...
3
votes
3answers
129 views

How to define this quick table macro?

I can use this to generate a simple table: \documentclass{article} \begin{document} \begin{tabular}{|p{.25\textwidth}|p{.25\textwidth}|p{.5\textwidth}|}\hline &&\\\hline &&\\\hline \...
1
vote
2answers
39 views

“Missing { inserted.” error when using \NewDocumentCommand command as a subscript

I'd like to create a custom command with an optional parameter, which could be used in math mode as a sub- or superscript. However, the following code: \documentclass[pdftex,11pt]{report} \...
1
vote
1answer
16 views

Endnotes doesn't call counter correctly

I am trying to send numbered observations to the last page, as shown in the following MWE. How can I obtain the correct numbers to be displayed at the last page? Thank you! \documentclass{article} \...
39
votes
4answers
2k views

TeX macro idioms, or: understanding advanced macros

I often find that when I look at solutions from the experts here, the macro definitions are completely inscrutable to me. Trying to use standard techniques one would use to understand code in most ...
3
votes
1answer
55 views

How to generate summary table automatically?

I have to generate a summary of impacts and actions in many enviromental reports. Sometimes there are two or more impacts in the analyses, so I have to create the lines manually in the table. Is there ...
6
votes
4answers
375 views

How to recreate \newenvironment and \newcommand with \NewDocumentEnvironment and \NewDocumentCommand in LaTeX3

In order to learn better about handling dynamic arguments and "blocks" like what you pass to a command/environment, I would like to try to write a wrapper function around \NewDocumentEnvironment and \...
18
votes
2answers
709 views

Is there a list of expandable TeX primitives? LaTeX? e-TeX? others?

According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro \numexpr being expandable, calculations are possible. ...
11
votes
2answers
480 views

Is there a package that allows to write correctly times in hours, minutes and seconds in mathematical mode?

I'm looking for a package, or even a macro that allows me to simply write duration calculations for young students. Like for example this (Lebossé-Hemery 1957 classe de sixième): I prefer this ...
1
vote
1answer
27 views

hyperrefs/hypertargets and counters in \newcommand

I'm trying to create a custom "theorem" environment so pandoc will generate a <div> with an id corresponding to the theorem name in the html. Hypertarget/hyperref work well for this, but I can't ...
15
votes
3answers
1k views

Ignoring space between empty/optional command arguments

(This may be a duplicate, but I could not find an answer among the pile of similar questions...) Suppose we have the following command: % <month> <year> <month> <year> \...
1
vote
1answer
32 views

Count Number of Occurrences as Numerical Input for Other Macro

I am trying to make lingmacros gloss automatically be aware of the number of columns it will need to produce. Basically, for the \shortex command, one of the inputs is the number of columns you want ...
3
votes
1answer
34 views

Fancy \Aboxed without redefining it

I'd like to define a fancy box in align environments while keeping the \Aboxed command as it is defined by default. What I got so far \documentclass{article} \usepackage{mathtools,tcolorbox} \...
1
vote
2answers
21 views

Todo to span multiple paragraphs

I can define a todo command like this: \newcommand\todo[1]{\textcolor{red}{TODO: #1}} This command does not work for multiple paragraphs with line breaks in between: \todo{hello world} How can I ...
3
votes
3answers
110 views

Newcommand with optional argument and ifthenelse

I would like to define a new command comp with two arguments where the second (and last) argument is optional, using 'ifthenelse'. I tried : \newcommand{\comp}[2]{% \ifthenelse{\isempty{#2}}% {{...
8
votes
2answers
230 views

TikZ, forest and star macro

I would like to define a star version of a macro to be used for the value of edge label. The second code does the wanted the job but its starred translation fails to work. Is there a subtil ...
0
votes
0answers
14 views

Delete fixed command name of a new command for constructing a title page

I am writing my thesis and I want to include the names of my promotors in the titlepage. I define the commands in an .sty file but I'm having trouble with the fixed replacement text. I have two ...
0
votes
1answer
37 views

combining soul package and color one in a newcommand

I have to use \st (from soul package) for crossing a line over a word in a text file. In addition, for presenting a specific replaced word instead of the first one, I use {\color{blue} second word}. ...
0
votes
0answers
43 views

The content of one command (`\thanks{}`) repeats two times

The document class file is iosatr2c, and if I use the command \thanks after the author name, then the text of the command \thanks will repeat two times. I want to know how to address such a problem。 I ...
0
votes
0answers
24 views

filecontentsdef: How to save a file data in a macro without creating a physical file in the working directory?

Following the description of filecontentsdefmacro environment in the manual of filecontentsdef, I understood that it can be used to save some data in a macro without the need to create a physical file ...
5
votes
2answers
137 views

Count digits of result of arithmetic operation

Based on J.Wright's answer I wanted to count the characters of an operation. Nevertheless the output of the code below is 16 12321 2 where instead of the bold number I expected to count the ...
20
votes
3answers
1k views

What is the exact purpose of \ftype@<TYPE>?

I currently working on some float related code an saw that the standard float environments figure and table define (beside others) the macros \def\ftype@figure{1} and \def\ftype@table{2}. The LaTeX ...
1
vote
1answer
40 views

Is \, | \, equivalent to \mid?

Is \mid equivalent to \, | \, ? I am asking this because, \mid does not cooperate with \big. However \,\big| \, works fine. I typically use these expressions when defining sets, for instance:
0
votes
1answer
54 views

Please help me write a macro to save file in “D:\latex\test_ddmmyy.tex” in TeXStudio?

I want to make a macro in TeXStudio to save a tex file under the name test_ddmmyy.tex (ddmmyy is current day, month, year) in the path D:\latex\test_ddmmyy.tex. Can you help me?
1
vote
2answers
46 views

Automatically reduce size of text to fit inside a frame

I need a code (and so, created that:P) for reducing the font size in order to fit it inside a frame (or a minipage of a frame) and not let it overflow from there to the footer's area. lets say we ...
0
votes
0answers
38 views

Improve a command for text annotation

Inspired by LaTeX package ruby @egreg's suggestion to the problem (Displaying pinyin over Chinese characters, without impacting word spacing) I implemented the following command with example of usage: ...
0
votes
1answer
24 views

Item enviroment with \hgnum command 2

There 2 packages from my last example: ideje.tex and mypackage.tex I need to complete this enumerate enviroment from arabic, roman to include hgnum begin{enumerate}[label=\roman{enumi}--\arabic{...
2
votes
2answers
87 views

How to define the symbol by command?

There is a notation: \mathbf{P}^{m}_{b}(n) How can it be defined using \newcommand ? PS The variables m, b, n should be as arguments
0
votes
1answer
35 views

Constant Counter is not working

I have a package for \hg and \hgunits as given here I wanted to use it like this: \item svoboda a volnost {\jednotky{22}} \item \def\aa{\value\modulo{152123}{10}} {\hg \hgunits{\aa} } HERE {\hg ...
71
votes
5answers
9k views

How can I see the “implementation” of protected commands such as \LaTeX?

After reading another question relating to how to see definitions of commands, I tried: \documentclass{article} \begin{document} \show\LaTeX \end{document} But this shows me in my logfile: \LaTeX=...
1
vote
1answer
65 views

counters in theenumi 2

I have the following MWE using counters. At which place can I insert \stepcounter to increase always at the next \enumerate item? All positions which I've tried have failed with \endcsname error. \...
13
votes
3answers
1k views

Apply a macro to every word

In order to improve the \sameword feature of reledmac, I would like to find a way to automatically apply a command to every word. For example, in plain TeX, \def\foo#1{#1 (#1)} foo bar foo bar foo ...
0
votes
0answers
31 views

Expanding user defined macros for compatibility

I have an annoying reoccurring problem. I often use user-defined macros with for example \newcommand in my LaTeX code. I also use LaTeX a lot in for example Jupyter Notebooks. Often Some things render ...
0
votes
0answers
31 views

changing \def to \edef causes error **job aborted, no legal \end found

Edit: Sorry forgot to add the intention: So my understanding is that \def expands the current definition, so I wanted to try using \edef which I believe is meant to fully expand the command even after ...
0
votes
0answers
29 views

Macro similar to section with label/reference and custom format

I am trying to write a macro (\exhibitTitle) that would behave similar to section/chapter, but with its own counter that increases by 1. Its important that it supports label (doesn't have to be ...
1
vote
0answers
38 views

Problem with implementing \ifcsname … \endcsname into a custom macro

I apologise in advance if this is a bad question but I have been trying to read up macros in Latex with the TeX-book but I just cannot work out why this doesn't work. So I have a 'working' macro (...
3
votes
4answers
73 views

How do I pad a string argument to a macro to a set length string

So I have a string being passed as an argument to a macro. This string could contain up to 10 characters, but I need latex to 'pad' the string out so it ALWAYS contains 10 characters (by putting ...
16
votes
3answers
2k views

How to temporarily replace Latin characters with Greek

Often I am typing equations with many Greek characters in them, and it becomes cumbersome to type out the commands for them all. I would like to make a command or environment that replaces Latin ...
2
votes
1answer
50 views

How can a macro detect if it's at a paragraph beginning?

I would like to write a macro that behaves differently at the start of a paragraph. How can I do this? (Ultimately I would like this macro to take an argument, but am assuming that's not relevant to ...
3
votes
1answer
60 views

How can I define a command like `\copypaste{ref-label}`?

How can I have a command like \copypaste{ref-label} such that it copy the corresponding environment to label \label{ref-label} and paste it where the command \copypaste{ref-label} is? or at least (if ...
0
votes
1answer
39 views

macros expanding to a TikZ node

I want to create rectangular nodes, given two coordinates bottom left and top right, with a macro. The difficult part is that I want to use the macro where a node name can be used; for example, in the ...
0
votes
0answers
55 views

Isn't it wise that LaTeX package developers, make an option in all their math packages…?

Question: Isn't it wise that LaTeX package developers, make an option in all their math packages something like \usepackage[opt-cmd[user-define]]{math-package-name} such that we able to use only ...
3
votes
2answers
57 views

Global Definition of a List

I found some sort of a list online and got it to work as intended The command "addtoaliste" is adding a parameter to the list "aliste". It's defined by newcommands, so I have problems getting it to ...
2
votes
1answer
63 views

Relabeling commands before redefining them

I would like to rename a couple of commands so that the commands match the words I think of when I want to use them. I would like to have \iso be what is by default \cong (an equals sign with a \sim ...
1
vote
1answer
42 views

Construct math super/sub-script from reference (`\ref`) with hyperref and cleveref being loaded

First, I would like to apologize for the insanely long MWE below. However, I wanted to keep it complete. At the bottom line I want to achieve a construction like $H^{\ref*{my-label}}_{\ref*{another-...
6
votes
1answer
229 views

How do I get the hue, saturation and brightness values from a color?

I want to define a new colour (myorange) by changing the hue value of a previously given colour (oldcolour), thus maintaining its original saturation and brightness. Is there a way for doing this? I ...
1
vote
1answer
53 views

Started to play around with custom commands and would love help with understanding LaTeX hack codes

This may be a lot to answer at once, but I've come across some code in an old thread (pasted below) and don't really understand how it works. I would greatly appreciate it someone could walkthorugh ...
0
votes
1answer
38 views

New Command acting around selected text

I would like to make a new command that allows me to quickly write the expectation value of an operator. It should put text in between other commands to make the following: $\langle \psi | text | \...
7
votes
2answers
216 views

How to have hashes doubled _and_ things expanded?

I'd like to learn some TeX programming technique which I can always apply for handling the same type of situation: The code \newtoks\mytokenregister \def\five{\four5} \def\four{\three4} \def\three{\...
1
vote
1answer
45 views

Using xstring to generate index keys

I have a document containing many instances of an environment with a mandatory argument providing a short "tag." These tags are something like "M04", and I've written a macro using xstring which ...