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.

4
votes
2answers
56 views

keyval - function for keyB should act dependent on value of keyA - how to do this?

I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package: I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
12
votes
1answer
102 views

pic versus macro in TikZ

Consider this code in the TikZ - PGF manual, which uses a macro % Main code from % The TikZ - PGF manual % Author: Till Tantau et al % Version 3.1.3, released May 9, 2019 % Page 40 \...
0
votes
0answers
22 views

Narrower kerning of symbols generated by Tikz [duplicate]

I'm using LaTeX to render a set of custom glyphs. Each glyph is perfectly rectangular, at a 3.5 x 5 aspect ratio, and they're defined something like this (the following example just lines the borders ...
3
votes
1answer
52 views

An understanding trouble with \framebox

I'm reading More Math Into LaTeX, and it introduces the command of \framebox at section 3.9.2 on page 91-92. There are the two following code examples which show different output: \framebox{\makebox[\...
3
votes
1answer
16 views

\newcommand for short notation for a \multicolumn [duplicate]

Many times is handy to define \newcommand for short notation for \multicolumn. For this purposes I test two definition for such commands: \newcommand\my[2]{\multicolumn{1}{#1}{#2}} \newcommand\mx[2][...
5
votes
2answers
317 views

How do I superimpose two math symbols?

I want to create a symbol that superimpose \top and \bot. I have done this \documentclass[12pt]{article} \usepackage{amsmath} \newcommand{\modd}{\top\hspace{-3.17mm}\bot} \begin{document} $\modd \top ...
5
votes
3answers
90 views

Looping over charts and names simultaneously

I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as ...
2
votes
1answer
33 views

Redefining \label to not default to <1>

According to this question, labels are defined by default on a beamer slide to always be defined at the first slide <1>. Indeed \show\label shows > \label=macro: ->\@ifnextchar <{\...
1
vote
0answers
20 views

Using pgfkeys to make a custom tikzpicture command with multiple use of addplot

Consider this MWE: \documentclass{article} \usepackage{tikz,pgfplots} \usepackage{pgfkeys} \usepackage{xparse} \usepackage{filecontents} % DATA 1 \begin{filecontents*}{data1.txt} 1 1 2 4 3 9 4 16 5 ...
0
votes
0answers
21 views

Setting defaults with keyval-interface - do it in the current scope or do it globally?

Assume a LaTeX 2e-macro, be it named \foo, which processes the content of one optional argument via keyval-syntax. E.g., \foo[key1=value1, key2=value2,...,\keyN=valueN] I would also like to have a ...
17
votes
2answers
331 views

Are there guidelines for finding good names for LaTeX 2e packages and control sequences defined in these packages?

I have written some code which I would like to submit to CTAN as a package for LaTeX 2e. (readme, dtx, ins, pdf with manual and commented sources.) I need a good name for the package. Question: Are ...
0
votes
0answers
15 views

Spacing of a macro similar to \sin [duplicate]

I want to create a macro \dom (for domain) that behaves similarly to \sin in the sense that it has spacing \, if it is followed by a letter such as in \dom a and that is has no spacing if followed by ...
7
votes
3answers
255 views

How to test if argument is a single space?

I am currently writing a document, that sometimes requires me to alternate the colors of the letters in a sentence. I thought it would be easy to find a way to create a macro that does that, but I've ...
1
vote
1answer
28 views

\dif command doesn't work as intended

I've defined the command: \newcommand{\dif}[1][]{\mathrm{d} {#1}\,} since I use the notation: \int \dif{x} f(x) so that there's a space after every differential. However, it doesn't work as ...
2
votes
2answers
21 views

macro within pgfplots in beamer

I want to create a macro so that in a beamer presentation it produces the same plot with slightly different data. But it seems as though a problem exists before I include an argument in the macro. ...
5
votes
3answers
171 views

How do I unravel apparent recursion in an edef statement?

The text book that I'm writing requires the ability to dynamically build an alphabetically sorted list. As to not invoke the overhead of high powered, general purpose packages, I have opted instead to ...
8
votes
2answers
196 views

Can I have a delimited macro with a literal # in the parameter text?

I'm trying to define a macro which grabs everything until the next # (parameter token). My twisted imagination wants something like this: \def\test#1###2{(#1)[#2]} \test hello#{world} to grab hello ...
1
vote
0answers
28 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...
6
votes
5answers
153 views

Appending to a command while also expanding a counter

I want to append some text to a command but expand a counter while doing so. Here is an example of what the problem is: MWE: \documentclass{article} \newcommand{\topics}{} \newcounter{topic} \...
0
votes
0answers
34 views

Is there a package for abbreviations management? [duplicate]

I wonder if there is a way to efficiently manage abbreviations. When I do my Ph.D. work, I usually copy the contents from one document to the other. When rewriting contents to a journal or for a ...
0
votes
1answer
22 views

Savebox from within enumerate [duplicate]

I'm completely puzzled by this: I'm trying to create a simple command that will modify a savebox from an enumerate, and I've worked it down to a minimal example of some weirdness: ... % Create our ...
0
votes
2answers
74 views

How to call a command accepting 2 optional args defined with `\NewDocumentCommand` and pass only 2nd optional arg to it (skipping the 1st)?

If \myB accepts two optional arguments, \myB sets both of them to default values, \myB[5] sets first to 5 and second to default value, \myB[5][10] sets first to 5 and second to 10. But how do we set #...
4
votes
5answers
234 views

How to epxand macro with optional argument equal to (x,y) so that it becomes part of \path(x,y)--(a,b); inside another macro (expansion problem)?

When \myCoordinate accepts MANDATORY argument, following works: \documentclass{standalone} \usepackage{tikz} \newcommand\myCoordinate[1]{#1} \newcommand\myPath[1][(1,1)]{\path[draw=red]\myCoordinate{#...
2
votes
1answer
17 views

Transforming string wrapped with double asterisks on both sides to a bold text

I am trying to convert **sometext** to bold. I came across the following snippet: \makeatletter \def\starparse{\@ifnextchar*{\bfstarx}{\itstar}} \def\bfstarx#1{\@ifnextchar*{\bfitstar\@gobble}{\...
1
vote
0answers
36 views

Is there a way to create a “function” that generates LaTeX code based on the parameters?

Context: I work as a statistican for a high school. One of my responsibilities is to generate performance reports for every teacher in the school, based on how well students evaluate them. I use ...
7
votes
3answers
224 views

Macro that takes any latex code as an argument

So I am thinking of creating a macro that takes any latex code as an argument. For example, \newcommand\purp[1]{\color{purple} #1} I hoped that this macro would make any latex code inside of \purp ...
1
vote
1answer
46 views

Repeat blocks of code

I'm looking for a way of repeating an entire part of a document n times. The documents I create look like the following : most of the time, I'm repeating half a page. This is because I print those ...
2
votes
2answers
58 views

How to use a string to form the name of an existing command?

In my project, I already have a file containing commands for names of my documents : \newcommand{\docOne}{Title of my first document} \newcommand{\docTwo}{Title of my second document} ... I've also ...
1
vote
1answer
61 views

ConTeXt Project Structure: Add metadata to component

I am setting up a project structure for a new journal and I want to use a structure like the one in this answer. However, instead of using document:start I tried \startsetups component:start, but no ...
2
votes
2answers
39 views

How can I force resized mathmode symbols to respect fontsize changes?

I want to make a latex symbol that contains a resized math symbol using \scriptscriptsize. However, when the scope containing the symbol is subject to a font resize, the \scriptscriptsize-ed symbol is ...
0
votes
1answer
60 views

Adjust photo macro to change format [closed]

Using the LaTeX CV template available under this Link (login: gafavekor@cyber-host.net ; pw: 123456) and I've realized that the picture is automatically cut to a vertical format. I would just like my ...
3
votes
3answers
76 views

Append unique characters read from filecontents to a string

I have a list of 2-character strings that is read from table, e.g. \begin{filecontents*}{attributetools.dat} Attribute SL SK MC SL AA PT SK UP MC \end{filecontents*} I want to create a string that ...
0
votes
1answer
48 views

What is the basic definition of \newcommand?

Awkward it is! I can not find the basic definition of \newcommand, though it is used a million times. I suspect it needs improvement.
2
votes
2answers
45 views

Add two macro results together

I have a macro for a word count in my overleaf document, its currently in each .tex section of my document, but I want to be able to add the results of them together (i.e. the word count of all ...
2
votes
1answer
51 views

Setting \crefname dynamically

My goal: \begin{equation}[singular=<sing_flag>,plural=<plur_flag>]\label{eq:1} a < b \end{equation} \cref{eq:1} yields <sing_flag> (1) for any input for singular and plural (...
4
votes
2answers
225 views

List of newcommands used

I have large files that I am inputing the beginning of my texts that contain all my \newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ? Is ...
3
votes
2answers
74 views

Set command option with document wide newcommand

I work a lot with the siunitx package and I've got many numbers with a high decimal precision. Now I'd like to be able to just copy these numbers in full precision in the relevant positions in text, ...
1
vote
0answers
87 views

How to change \scantokens to \tl_rescan:?

After reading the documentation, reviewing the forum and seeing the comments, I have tried to move a code that I have using \scantokens to \tl_rescan:. I want to save the result in a variable and ...
2
votes
3answers
145 views

Multiple options for Pseudonyms

I'm looking for something fairly similar to this problem, of defining macros to print pseudonyms for people, but I'm not sure how to modify it (or if it is actually the right approach for what I'm ...
1
vote
1answer
23 views

Define an environment from tcbhighmath

Let's assume that I have defined very carefully the parameters of the highlight math style from the tcolorbox package. I would like to define an environment \newenvironment{equationbox}{% \begin{...
4
votes
1answer
79 views

Seemingly unused \edef prior to an \ifx mysteriously affects the outcome of the \ifx. Why?

It is my understanding that in \ifx\x\y xx \else yy \fi, \ifx does NOT expand its arguments. If you want \ifx to compare the expanded values of \x and \y, then we need to do the expansion ourselves ...
1
vote
1answer
47 views

Looping over characters in a string and applying a macro with an additional argument

The following code was kindly provided for me in TeX Chat by @egreg. This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace \...
3
votes
2answers
54 views

Expand macro inside lstlisting and apply syntax highlighting

I'm wondering if there's a way to expand a macro inside a lstlisting environment which automatically applies syntax highlighting to the expanded text. For example, the listing in \documentclass{...
0
votes
1answer
43 views

Illegal parameter number in definition

I found a nice solution to edit the look of hyperlinks, but I have another problem: \documentclass{article} \usepackage{hyperref} \newcommand{\link}[1]{\href{#1}{#1}} \begin{document} % error: ...
0
votes
1answer
46 views

Is there a way to define \xmat*{M}{n}{m} in the physics package

As titled, I want the command\mqty(\xmat*{M}{n}{m}) to generate a matrix like this: $$ \begin{pmatrix} M_{ 11 } & M_{ 12 } & M_{ 13 } & \cdots & M_{ 1m } \\ M_{...
3
votes
1answer
135 views

Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse?

this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'...
0
votes
0answers
56 views

Typesetting journal names and abbreviations

I am confused. What is the proper / accepted way of using the journal macros in bibliography? I have found about 3 different sources, and each of them has an incomplete set of the journal macros that ...
0
votes
1answer
31 views

How to activate or deactivate babel layout locally

Consider this example, how to deactivate tabular layout in RTL context \documentclass{article} \usepackage[nil,bidi=basic-r,layout=counters.lists.tabular]{babel} \babelprovide[import, main]{arabic}...
1
vote
2answers
40 views

Listing in a command error: Text dropped after begin of listing on input line

While I wanted to test some alignment options to ask another question regarding to listings, I have encountered a problem that I was not expecting. Consider the following code: % Preamble \...
4
votes
2answers
258 views

Keep at all times, the minus sign above aligned with minus sign below

How can I change the frg command such that I can create and maintain at all times the minus sign above aligned with minus sign below? PS: If you can show how to include a font setting for the whole ...