Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
41 views

Get a typesetted output of a macro back as a replacement text for another macro

Let suppose you have a recursive TeX macro \formula (with inner control sequences advancing local counters), which once expanded and typsetted outputs an expression that meets all your needs: for ...
0
votes
1answer
28 views

Newcommand that uncludes a foreach with unknown number of parameters

Sorry, but part of the code is in French. However, it won't matter because it's only the listed text I currently have a new command named \listerfe that, combined with \listerfenextarg and \...
4
votes
2answers
37 views

How to evaluate an expression and use the result in newcommand?

I am trying to declare a newcommand \newcommand{\seq}[3]{#1_#2, #1_{#2 + 1} \cdots ,#1_#3} What I want is basically to print the sequence $v_0, v_1, \cdots, v_N$ by calling \seq{v}{0}{N} but it is ...
0
votes
1answer
54 views

Setting superscript for custom symbol

How do I set a superscript for my custom symbol generated with \newcommand*\mysymbol{\includegraphics{mysymbol.eps}}? Default superscripts appear way too far right from the place they should be in. ...
0
votes
0answers
44 views

Unwanted offset in \widehat command [on hold]

The visual representation of the \widehat command in Overleaf recently changed against my will. When I type \widehat{X} the display in the pdf more closely resembles \widehat{}X, placing the hat ...
5
votes
2answers
92 views

\newcommand: Combine (optional) star and optional parameter

How may I define a new command that admits starred and non-starred variants, and that also admits an optional argument? I tried the following: \documentclass{minimal} \makeatletter \newcommand\...
0
votes
0answers
27 views

Outputting a custom glossary to a separate file

I'm working on the translation of a German book and have created the following macro so as to link some translated words and expressions to their original, which then I print at the end of the ...
2
votes
3answers
48 views

How do you pass the result of a command as an argument for a command?

I'd like to generate a string and save it for later use. However, it saves the command instead of the string in the following situation: \newcounter{Counter} \newcommand{\ParentNode} {NULL} \...
2
votes
2answers
109 views

Detecting subscript in command argument

I have defined a command low that adds a subscript to an argument: \newcommand{\low}[1]{{#1}_{l_{\mathcal{A}}}} However, if the argument of low contains subscripts itsself (for example in the case ...
0
votes
0answers
23 views

Shortcut for \begin{equation} - recognized as math by Texmaker

When typing a math report, I want to use my prof's advices: he defines shortcut for equations: \newcommand{\be}{\begin{equation}} \newcommand{\ee}{\end{equation}} This makes it much easier to use, ...
0
votes
1answer
38 views

How to color specific word in a paragraph more times?

Maybe the title is a bit misleading and it's my pilot post on here :) Anyhow, I have a paragraph with ,let's say 100 words, from which 10 of those words are word "dokument". I have to make a command ...
1
vote
2answers
49 views

How to correct the following newcommand?

I am declaring a newcommand as follows: \newcommand{\code}[2]{ \begin{listing}[ht] \begin{minted} [ framesep=2mm, baselinestretch=1.2, bgcolor=blue!30!white, fontsize=\footnotesize, ] {#1} #2 \end{...
0
votes
0answers
32 views

Preprocess a .tex file and save it as a new file

I have several .tex files that I would like to share with other people. I've included in them (with the command \input) several files with macros that I've written myself. However, I would like to ...
4
votes
2answers
50 views

How to use correctly \dl with vectors using the diffcoeff package?

I am showing the following question about the use of differential \dl in section six of the user guide diffcoeff. Why does not the command\dl \vec{x} work? When dealing with the unknown x, the ...
2
votes
2answers
43 views

Define cover colors based on current month

I am writing a style guide documentation and I want to make visually appealing what the document was updated using the cover color. The main idea is to automatically update cover color based on the ...
1
vote
1answer
36 views

Stretching table

I defined a custom command to produce a table I have to do for various experiments: \newcommand{\exptable}[3]{ \begin{center} \renewcommand{\arraystretch}{1.5} \begin{tabular}{ccc} \...
1
vote
1answer
34 views

LaTeX with markdown and tables

I'm trying to build up a new documentation system using Markdown and LaTeX. After several hours most things are running smooth, but tables are a bit complicated. Most of the text can be written with ...
9
votes
3answers
206 views

\newcommand: Using one parameter as the default for the other

I would like to define a macro that takes two arguments, one of which is optional. If it is not given, then it should take the other one as default value. Unfortunately, \newcommand{\mycommand}[2][#...
1
vote
3answers
40 views

Using \StrSubstitute in a macro definition

I would like to create a macro that typesets the argument using \emph and also creates a label with that name. My names contain underscores so I tried to use \StrSubstitute from the xstring package: \...
2
votes
2answers
219 views

How do you write a macro that takes arguments containing paragraphs?

I'm trying to write a macro that takes arguments containing paragraphs. If you write a normal macro and one of its arguments contains a paragraph, it will break: \documentclass{article} \usepackage[...
-1
votes
1answer
81 views

Use variables like #1 in math [closed]

I'm writing this small \newcommand, and I want to send numbers as parameters. But since the math mode always tries to interpret the # in a different way. I don't know what to do. Here is what I have ...
1
vote
1answer
55 views

help: looking for a generic (and elegant) array (variable) map syntax to keep stuff

My apologies if this has been discussed elsewhere, but if it was I couldn't find it. I am the author of a template for academic thesis for my university, but I'm definitely not a TeX expert. In this ...
3
votes
2answers
58 views

How to cumulate texts at the end into various groups?

Please help: I am editing a .tex file (memoir class) with lot of text, and I want to collect sentences like important questions, quotes, words, etc and collect them into their respective groups and be ...
0
votes
1answer
41 views

Expansion of macro in environment argument

I'd like to generate an environment that changes a bit according to an argument given for it. The reason is having different locales in the document. I have defined a command, EmitLanguageStr that ...
1
vote
1answer
44 views

Generalising a second-order macro with loops

I'd like to construct a macro that can be used to define commands. Those commands behave like variables or structs of variables, such that they can contain multiple values. The "member" is passed via ...
3
votes
3answers
256 views

How to define a macro with multiple optional parameters?

After I had a macro that worked, I tried to improve it by making some parameters optional. Unfortunately the macro no longer works. Instead I'm getting errors I do not understand, for example: LaTeX ...
1
vote
1answer
128 views

What is “# Notation”? How does the # syntax work?

Closely Related: How to implement \expandbefore, similarly to \expandafter? In the related question, a reference is made to the "# Notation". How does the syntax work? From an answer on the other ...
3
votes
2answers
124 views

How to implement \expandbefore, similarly to \expandafter?

I am trying to define a new command, but specifying the new control string "on the fly" using csname and endcsname. (This is for the purpose of implementing a dependency injection pattern.) **...
0
votes
0answers
24 views

How to pass argument for `\includegraphics[width=..]..` without causing “Runaway argument?”? [duplicate]

I'm going to despair: It seems nobody has a problem when passing an argument for the width of \includegraphics, but I always get Runaway argument?. Whenever I remove the [#2\textwidth] from my command ...
10
votes
3answers
192 views

Macro only to be defined in math mode

I often use short macros in mathematical formulas for frequently used symbols, e.g. \d x for a differential dx or, say, \v if I need a vector v very often in my text to make things more readable. ...
1
vote
2answers
188 views

Transpose a matrix and parenthesis

I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs. \transp{A} is the matrix A^T between parenthesis, \transp A is just the ...
1
vote
3answers
47 views

modular macro list structure to iterate it

Based on the Wipet's answer, and with the same learning spirit, about the iterate loop "for", it's interesting to find out how the proposed "for loop" could be more modular. I want to pass, as an ...
2
votes
3answers
69 views

String variable with multiple values

I'm after a definition of a command that could have multiple values to use in different contexts. The use case for this would be in a custom class that uses two languages simultaneously, or I guess ...
2
votes
1answer
30 views

Count authors of a bibliography entry

I would like to have a command that would give me the number of authors of a given bib entry. What I have unsuccessfully attempted so far was to create a key-value storage (prop), hook on the bbl ...
1
vote
0answers
29 views

Prevent selection of some pdf sections

In order to avoid the selection of a part of a pdf, I use this command: \usepackage{accsupp} \DeclareRobustCommand\squelch[1]{% \BeginAccSupp{method=plain,ActualText={}}#1\EndAccSupp{}} For ...
0
votes
0answers
64 views

How to create my own table/figure environment with alignment of the caption on the left [without package]

I want to create my own environment for tables and figures in such a way that the caption is aligned to the left and the formatting caption uses a dot instead of a colon, e.g, Table x. My caption ...
3
votes
1answer
59 views

using \def in \newcommand

Consider this example: \documentclass{report} \def\startnewpart{FALSE} \makeatletter \renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi ...
1
vote
1answer
26 views

Missing characters inserted when using new commands in equations

I'm having a problem that I can't seem to fix. I would like to define a math symbol, and shown in the code snippet, which I use frequently throughout the text. When I want to include this same symbol ...
4
votes
2answers
77 views

Force linebreak, so that each subsequent line gets longer

Hej guys. Our institute has some special format requirements, and I'm wondering if one of these can be automated by some clever LaTex wizardry: A caption (also sections and subsections) is set ragged-...
0
votes
0answers
34 views

How is the correct way to use “\ tl_rescan: nn” and “\newlinechar” in xparse?

I am trying to implement a new environment using the xparse andfilecontentsdef packages. I have some complications with the use of \tl_rescan:nn and \newlinechar. The idea is to generate a new ...
0
votes
1answer
56 views

Environment with two optional arguments

I want to create an environment that receives an argument and an optional argument in such a way that the first argument will be a title and the two optional argument will decide whether the title ...
2
votes
1answer
109 views

How do I customize Circuit_macros in listings?

MWE; \documentclass{article} \usepackage{xcolor} \usepackage{listings} \definecolor{Others}{RGB}{0,110,40} % Green \definecolor{Character}{RGB}{146,76,157} % Purple \definecolor{Number}{RGB}{176,...
2
votes
2answers
46 views

How to expand definition before giving it as argument to exsheet environment

I'm trying to write exercise sheets in a modular way: Each exercise has its own file with question/solution environments as provided by the exsheets package. The exercise sheets then \inputs the ...
7
votes
1answer
87 views

Can \relax be replaced by a space?

LaTeX defines \vec as \DeclareMathAccent{\vec}{\mathord}{letters}{"7E} which eventually is expanded to \mathaccent"017E\relax whereas plainTeX defines it as \def\vec{\mathaccent"017E } replacing ...
1
vote
4answers
49 views

Including categorical colours with \newcommand in PdfLatex

I wish to have a list of predefined HTML colour codes and convert them into a numbered reusable variable which can then be referenced later. This is useful when having a set number of variables or ...
2
votes
2answers
92 views

LaTex - perform algebraic operations on variables

Suppose I've got the following document: \documentclass{article} \newcommand\mass{30} \newcommand\acc{9.8} \newcommand\force{\the\numexpr \mass * \acc \relax} % F=m*a \begin{document} \section{...
2
votes
1answer
84 views

LaTex - Exact math

I am quite new to LaTex and I am wondering if it's possible to use exact math in LaTex. I.e. I want to feed the script some input, which may be either a number or a variable, and it should perform ...
3
votes
3answers
167 views

Unbounded number of arguments - Good practice

Here is how I do to work with unbounded number of arguments of a macro. Is there a better way to do that ? \documentclass[12pt,a4paper]{article} \usepackage{ifmtarg} \usepackage{nicematrix} \...
0
votes
0answers
39 views

Pre-define complicated math operators

Problem I am trying to find a easy way to write Rademacher complexity so that I just need to write different index, function and constraint every time. Like defining partial derivative I previously ...
11
votes
1answer
120 views

Combine `map` and `use` expl3 macros

I'm trying to build a macro that processes a comma-separated-list of elements so that: \MapAndUse{a,b,c} would produce: My first intuition is to use a expl3 combination of \seq_map* to process each ...