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.

0
votes
0answers
28 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 ...
9
votes
3answers
224 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
247 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
50 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
147 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
32 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
33 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 ...
2
votes
1answer
82 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
33 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
97 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
1answer
74 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 ...
1
vote
1answer
119 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
52 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
92 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
57 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
109 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
86 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
176 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
50 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 ...
10
votes
1answer
135 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 ...
2
votes
1answer
51 views

How to display string variable without hanging texworks

I was getting unexpected results storing a parameter into a string variable, and added the statement "\str_show:N \l_tmpa_str" to produce debugging output. Texworks treats the output as an error. My ...
1
vote
1answer
47 views

Making a new command for tabular environments with flexible table sizes

I'm trying to create essentially a "new command" or "new environment" with a tabular environment. Is there any possibility to make a simple command that allows me to enter the size of the table and ...
4
votes
5answers
137 views

How can I access and store the current value of a counter?

My counter is being updated by a command and I want to save the current value + 1 of this counter at a specific point so that later on I am able to print it out. \newcounter{counterA} \newcounter{...
1
vote
3answers
87 views

More efficient way to define a macro

I want to write a macro to define some text, for example header title. User will use it like: \headertitle{Some header for a document} I wrote it this way: \newcommand\Headertitle{Default header ...
3
votes
2answers
151 views

Sort list of elements created from a custom command

In order to have this result I wrote this command: \newlength{\boldAcrwidth} \setlength{\boldAcrwidth}{2cm} \NewDocumentCommand{\boldAcr}{m >{\SplitList{ }}m}{% \makebox[\boldAcrwidth][l]{\...
2
votes
1answer
87 views

ConTeXt Mark IV: What is the Identifier rule?

What is the restriction on user-defined identifiers in ConTeXt Mark IV? Should it contain Latin alphabet only? What about numbers? What about hyphen and underscores? I can't find the official rules ...
0
votes
0answers
25 views

Using optional argument in closing statement of new environment

The answer 969/29410 showed that it is possible to use optional arguments in environment definitions: \documentclass{article} \newenvironment{hello}[1][world]{\noindent Hello #1, }{Bye now!\\} \begin{...
2
votes
3answers
100 views

Different behavior if no arguments

This is similar, but not a duplicate of Special behavior if optional argument is not passed and Different macro behavior when supplied an argument. I want to define a macro \XXX such that \XXX{1} and ...
0
votes
0answers
44 views

Conditional compilation within a macro?

I'm trying to define an environment that is conditionally complied in lualatex. The two solutions I've tried are the following: \documentclass{article} \newenvironment{test}{\ifx\X y \\ }{\else \\ \...
2
votes
2answers
43 views

Formatting output for \newcommand with for loop

I have the following minimum example \documentclass[12pt]{article} \usepackage{pgffor} \newcommand{\formatlist}[2]{ {x^#1} \foreach \x in {#2} {,x^\x}} \begin{document} $$\formatlist{5}{6,7}$$ \end{...
3
votes
1answer
148 views

Automatic theorem list

In the accepted answer to Code between \begin{environment} and \end{environment} stored in an array it's shown how to create an automatic list of theorems using expl3 syntax. However the \...
4
votes
2answers
137 views

why this \newcommand doesn't work in \align environment?

I'm trying to use the 'newcommand' in the environment 'align', for that I created the 'newcommand' \rbel that is an 'arrow' with a 'n' below It. I put all the packages that I'm using. \...
1
vote
1answer
49 views

Scope Problem in a newcommand definition

I am a LaTeX beginner, I am having trouble trying to implement the following code \documentclass[a4,11pt]{article} \newcommand{\site}[1][http]{{\bfseries #1://}} \begin{document} \site{www.tug....
3
votes
1answer
50 views

Dynamic change text with different Definition

I must print my PDF file often with 2 options: A or B. When I change contents of file, it's often error-prone when so much positions in document must be changed. Now I want use dynamic change: ...
4
votes
1answer
94 views

Is there latex3 work being done on a boolean case statement?

Various languages have constructs like select; when <expression 1> then <action 1>; when <expression 2> then <action 2>; ... when <expression n> ...
10
votes
5answers
667 views

A command challenge

Here's a little challenge. The goal is to create a command that takes is two or three arguments without using square brackets for optional arguments. The first and second argument are separated by a ...
3
votes
2answers
72 views

Strange result with patch of \overarc

Triying to use a patch for \overarc from this answer https://tex.stackexchange.com/a/409106/54817 I got this result \documentclass{article} %\usepackage{fix-cm} \usepackage{arcs} \usepackage{...
1
vote
1answer
30 views

shortcut macros not working in TeX4ht

\documentclass{book} \begin{document} \newcommand{\testscsar}{E_c} This is for test $Ec\testscsar$ \end{document} Above code works everything fine to generate HTML conversion, but if I place the \...
1
vote
1answer
77 views

tabularx repeat headers at the start of each new page

I am trying to write a latex template for math dissertations for my university and I have gotten most of the formating built into the appropriate class file. However, one issue that I'm not sure how ...
1
vote
1answer
33 views

newcommand for picture tikz matrix, wich separator to use?

I would like to create a new command to easily insert 4 pictures that will be arranged in a matrix, but I don't know wich separator to use in the main file. I always get the latex error "unknow ...
7
votes
2answers
127 views

Problem with my understanding of expandafter and newcommand with arguments and sout

I've tried for days to get my head around the expansion of code. Sadly, I don't get it. I try to pass a command with arguments as an argument to sout. \documentclass{article} \usepackage{ulem,lipsum}...
2
votes
0answers
128 views

Create an adapted \color macro for RTL mode (pdflatex and xelatex)

This is a complement to these questions: Colors bizarre results with right to left text Change color method used with beamer My aim is to create a macro like \color which can be used in RTL mode (...
1
vote
2answers
47 views

Command for Pretty Printing a Poll/Voting as a table (Splitting Parameter Value)

I want to write a command for writing a poll. My Plan is: \poll[<sumofvotes>]{<Poll title>}{ OptionA: <Votes for A> OptionB: <Votes for B>* OptionC: <Votes for C> ...
3
votes
2answers
71 views

\str_case:nnF not finding match

I have written a command using expl3 that is supposed to behave differently if the optional argument is specified as * or **. The command is intended for a math environment, and is supposed to render ...
2
votes
1answer
58 views

Define a command (like table of contents) but for attendees

I am writing a templat/class for a club that should be used for official protocols of meetings. Therefor we need a table of attendees at the beginning of the protocol and at the point where the ...
7
votes
3answers
165 views

macros inside tikzpicture

I wanted to make a bit more readable the tex code I'm using and, in this respect, I wanted to somehow use a macro for the following code: \draw (10 mm,10 mm) -- (20 mm,10 mm); I've created the ...
1
vote
0answers
25 views

Macros passing arguments of different data types [duplicate]

I'm new to LaTeX and quite impressed with this program! So, I'm willing to concede not being entirely certain that the issue I'm having has to do with data types, or just using \includegraphics{} ...
2
votes
1answer
58 views

math mode parsing in NewDocumentCommand

I came across the following NewDocumentCommand (source). \NewDocumentCommand{\expn}{gg}{% \IfNoValueTF{#1} {% \Exp } {% \IfNoValueTF{#2} {% \Exp\!\left(#1\...
1
vote
1answer
28 views

Strange error defining a macro with arguments for math mode

When I delete the second \item, it compiles fine. However, with the second \item, I get ERROR: Missing $ inserted and the math renders incorrectly: \documentclass[12pt]{article} \newcommand \frob[2] ...
1
vote
1answer
72 views

Compile to PDF file with different name than the source

I have a latex document containing some problems and their solutions. I also have a macro \excludecomment{sol} which if uncommented, excludes the solution environments. (Similar command is there for ...