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
4
votes
2answers
58 views

Is there a way to use string manipulations to make macro names?

Bottom line up front: what is a convenient way to input a particular character string into a \newcommand call so it can be manipulated to create multiple macro names? In particular, input (say) ABC ...
0
votes
1answer
25 views

expand macro before using as param for listing in newcommand

I wanted to create a parametrized macro (using newcommand) for my listings: It works as long as I use text as input parameter. Once I switch to macros as parameter it doesn't work. I have the ...
0
votes
1answer
26 views

how do I create a macro for two-way links?

I'm trying to extend a previous href command (that works) to create a pair of new commands that wrap \hyperlink{}{} and \hypertarget{}{}. The commands would work together to create hypertargets for ...
2
votes
2answers
31 views

How to escape characters being entered into the qrcode package

I am sure this has been asked before in some form, but I can't find an example, so. What I have are two variables (coming from an external system) x and y. I would like to encode them one on each line ...
2
votes
2answers
67 views

Problem with \newcommand and \renewcommand

I am trying to define a command called \vec{} that prints a bold and non-italic symbol in math environment. \renewcommand{\vec}[1]{\mathbf{#1}} usually works for me, but not in the documentclass ...
3
votes
1answer
45 views

New Environment with spacing issues for equations

Preety often i write equations with evenly spaced objects to be centered, like \begin{equation*} \hphantom{ \hspace{1cm} {(x\in X)} } f(x) = Ax + B \hspace{1cm} {(x\in X)} \end{equation*} which ...
2
votes
1answer
41 views

newcommand in tcolorbox

I am useing a lot of tcolorboxes and i would like to set them up with newcommand in order to save time. I use \begin{tcolorbox}[breakable, enhanced jigsaw] test test \end{tcolorbox} I ...
2
votes
1answer
31 views

Conditionally formatting numbers using a \newcommand

I want to create a command the prints a number in red if its negative and green if it is positive. I have tried: \documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{ifthen} \...
1
vote
1answer
35 views

Modifying a Makeindex Algorithm to Remove Page Numbers on a Selective Basis Only

I have extracted the following code from an answer in Remove page number from index entries which removes the page number from each index entry: \documentclass{article} \usepackage{xcolor} \usepackage{...
0
votes
1answer
33 views

Understand commands of a class file

I haven't much experience with TeX/LaTex and I am trying to write a CV based on this repository. Specifically, I am trying to understand how a LaTeX class file is written, and reproduce to a certain ...
3
votes
2answers
63 views

Conditional title in tcolorbox: not equivalent to an untitled box when empty

Consider the following code : \documentclass[10pt]{article} \usepackage{ifmtarg} \usepackage{xcolor-material} \usepackage[most]{tcolorbox} \makeatletter \newcommand{\makeboxtitle}[1]{\@ifmtarg{#1}{}{\...
5
votes
2answers
123 views

Reducing spaces in tikz macro

I want this: I got this: With this code: \documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usetikzlibrary{positioning} % overhead arrow \newcommand{\arrowlefto}[2]{ \begin{...
0
votes
1answer
21 views

Valid newcommand construct dumps me out of mathmode

I have defined \newcommand \xbar[1] {$\overset{-}{#1}$}. \xbar{arg} works fine except in equation environment. When I use it in equation environment (as in: \xbar{x} = formula) it drops me out of ...
0
votes
1answer
32 views

MetaPost: mpost and plain.mp

Am I right that 'pure' MetaPost (mpost), without plain.mp, knows only primitive commands? So that MetaPost compiler + plain.mp is like a pure TeX + PlainTeX or TeX + any other macros package? Is it ...
0
votes
1answer
25 views

Help with custom header command?

Consider the following MWE: \documentclass{article} % HEADER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{tikz} \usepackage{xcolor} \newcommand{\header}[2]{% \begin{...
4
votes
1answer
60 views

Newcommand with two optional arguments, one at the end

I would like to define a new command with two optional arguments, one at the end. This works: \newcommand{\matr}[3]{{}_{#1}\textbf{#2}_{#3}} \matr{b}{M}{e} But I would like to call it like this: \...
0
votes
1answer
58 views

"Undefined control sequence" when using footnote-to-endnote MWE

I'm seeing the following error "Undefined control sequence" when using MWE below ... ./Fnote.tex:15: Undefined control sequence. \hyper@normalise ...M{ }\catcode `%\active \let % @...
1
vote
1answer
22 views

MetaPost vardef: how to declare a variable of type 'expr'?

I want to make a macro swap: vardef swap(expr a, b) = save tmp; expr tmp; tmp := a; a := b; b := tmp; enddef; But there is an error when compilating: ! A statement can't begin with `expr'. I ...
0
votes
0answers
43 views

newcommand inside newcommand not working

I often use \newcommand inside another \newcommand, and it usually works well. But not this case: \documentclass[10pt]{article} \usepackage{amsmath} \begin{document} \bgroup \makeatletter \...
2
votes
2answers
37 views

Every token between active chars to fixed hbox

I would like to type something like this: |--1-23-|--4-5---| and get such output that every | is a vertical line, every - appears like \rule[.8ex]{1em}{.5pt}, and all other (non-active) characters ...
0
votes
1answer
61 views

Script {} in latex

So I'm writing my master thesis and I was wondering whether there was a way to script a custom \Laplace function in Latex. I want to write \Laplace(input) and get the output \Laplace \{ input \} as my ...
6
votes
2answers
152 views

Unexpected newline (catcode magic)

I am playing with Tex catcodes and hboxes. The following code should produce three lines of output: A...1... B...2... C...3... However, for some reason it makes a line break between A and ...1..., ...
5
votes
4answers
470 views

Change the meaning of \d for one character

I'd like to change the meaning of \d{} from under-dot to over-dot just for the characters c and C. That is, \d{c} and \d{C} will mean \.c and \.C, respectively, but \d{} will retain its original ...
2
votes
2answers
132 views

tabularray: How to comment out some rows using \if condition inside a table stored in a macro?

The following gets me this error ! Incomplete \iffalse; all text was ignored after line 26. So, how to make \if work inside the table stored in the macro \MyTable? \newif\ifShowRow \ShowRowfalse \...
0
votes
1answer
30 views

How can I use \lstdefinestyle in a subfile?

Assume that main.tex is my main compiled latex file. The rest of them (as sub.tex) includes the list of def ones in order to arrange each chapter, subchapter etc. How can I use defined style in main....
2
votes
2answers
97 views

Pass a variable from makefile to latex code

I wrote a simple makefile to compile my latex code. I have some variables in that makefile and I want to pass them to the latex code, but I don't know how to do that. Example 1: in makefile: # set ...
0
votes
0answers
43 views

customising ISBN, location, venue, volume, edition, series, dates, etc. fields of books, proceedings, etc. in biblatex APA style

I have the following MWE: \RequirePackage{filecontents} \begin{filecontents*}{biblatextest.bib} @article{W00, author = "Wayne, J.", title = "Article with volume number and doi",...
7
votes
3answers
193 views

Are there any LaTeX commands (including in packages) where the argument will be in math/text mode based on context?

As I work on the parser for finl, I'm contemplating how I'm dealing with command parameters and wondering if my current setup is sufficient. Right now, a parameter has a type which would either be ...
1
vote
1answer
34 views

Macro building coordinates breaks \addplot command in pgfplot

I would like create a plot of a few data points that are defined at the top of the document using something like: \newcommand{\test}{{3,4,2,5}} To do this, I created a macro that parses these values ...
10
votes
5answers
423 views

Test if an argument starts with a particular string

Is there a way in tex to test if an argument starts with some string or not? And then extract the text that follows that start? As an example, I want to define a command that makes a text bold if it ...
4
votes
4answers
222 views

Same command with two different argument-separators

I have the following code \makeatletter \def\ip#1{\@ip#1\relax} \def\@ip#1|#2\relax{\langle#1|#2\rangle} \makeatother When in the document one finds $\ip{2|3}$ he gets something like <2|3>. ...
1
vote
1answer
62 views

TeX Definition to Suppress Page Number Conflicting with Macro to Make Other Page Numbers Bold

In the post Is There a Command Analogous to \addtocontents{toc}{text} for an Index?, I inquired as to the existence of a command that could be used to add a comment to the Index in a manner analogous ...
2
votes
1answer
27 views

Delimiter error using nested commands [duplicate]

I'm not an expert on TeX and I've run into a problem. I've been able to condense it into the following minimal working (or rather not working) example: \documentclass{article} \usepackage[utf8]{...
2
votes
0answers
49 views

new command within table parameters

I used \newcommand to define a variable and I used that variable in one of the table parameters but that produced an error Here is my code: \documentclass[a4paper,11pt,english]{report} \usepackage{...
3
votes
1answer
55 views

What's the difference between \newcommand{\cmd}{defn} and \newcommand\cmd{defn} [duplicate]

Documents I found about \newcommand only uses \newcommand{\cmd}{defn}, and doesn't talk about \newcommand\cmd{defn} form, but I see \newcommand\cmd{defn} form frequently, especially in nested ...
3
votes
6answers
137 views

How are conditionals expanded in TeX?

I am typesetting a collection of mathematical problems, solutions and notes to them in Plain TeX. The simplified document is: \def\problem{Problem. } \def\solution{Solution. } \def\note{Note. } \...
0
votes
1answer
62 views

Is it possible typeset a \numexpr-calculated number stored in a macro without having to use \the?

For the MWE below, using \the with \NextShiftIndex makes the document run correctly, however, I would like to know if it is possible to make the calculated number stored in \NextShiftIndex not need \...
4
votes
4answers
206 views

Automatically filling in accents/diacritics for characters in LaTeX

There are a number of times when I'm writing LaTeX documents when I need to write a character with an accent or diacritic in it. For instance, the "ô" needed to write "L'Hôpital" (...
4
votes
1answer
55 views

How to customize style of section and subsection numbers when used in headers?

TL;DR - Why am I getting errors with the last line of \usepackage{xstring} \renewcommand*{\thesection}{\alph{section})} \renewcommand*{\thesubsection}{\StrGobbleRight{\thesection}{1}.\roman{subsection}...
2
votes
1answer
32 views

xparse - order of token-type args

I am curious if there is a technical reason that the token-type args of xparse must follow the correct order? MWE \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\foo}{s t+}{--- \...
0
votes
1answer
51 views

Trying to write a newcommand to wrap text in bold parentheses

I am attempting to define a command \ideal that will wrap its argument in bold parentheses. Here is my attempt: \newcommand{\ideal}[1]{\boldsymbol{\left(\right.} #1 \boldsymbol{\left.\right)}} This ...
3
votes
2answers
121 views

newcommand problems

I am working with \newcommand and \ifdefined. I have an issue with the below code as it produces an error and I don't know what is wrong: \documentclass[a4paper,11pt,english]{report} \usepackage{...
2
votes
1answer
31 views

if condition problem with newcommand

Hi all I wrote a simple code at which I created simple variables and some If condition. The output however was not desired Here is the code: \documentclass[a4paper,11pt,english]{report} \usepackage{...
2
votes
1answer
30 views

Fixing macro for siunitx backwards compatibility

I am encountering errors with my below code (contained in a loaded .sty file; packages appropriately loaded beforehand), which is part of my attempt to ensure siunitx3 compatibility for older code, ...
0
votes
0answers
26 views

Same title for every tex template

I have a TeX document that includes several TeX documents. The question is that the contents of the attached documents are different and the number of pages may also differ, but I need the same text (...
8
votes
2answers
99 views

How does \expandafter interact with } and \toks?

I know \expandafter can skip the token immediately after it, therefore I try to use it with some combinations of } , \toks and definitions with \def and \let. The main question the puzzles me is why ...
2
votes
1answer
94 views

merge many txt to one

There are plenty of .txt files and I try to figure a way in Latex to merge all *.txt to one *.txt. I thought about \newread and \newwrite but I don't know if there is a better way or how to start. the ...
1
vote
1answer
40 views

Build a command for article contracté in European languages

I would like to build a command \contraction{<prep>}{<art>} to do the "article contracté" in European languages. For example, I would like to have \contraction{de}{le} return du ...
15
votes
6answers
1k views

Parse WolframAlpha's matrices into LaTeX

I sort of have the same issue as this question, but the reverse. It is often the case that I need to write out a matrix in LaTeX, one resulting from a computation of some sort. Of course, the ...
1
vote
1answer
57 views

Gobble command not gobbling the arguments of footnotemark (inside a authblk definition)

I am editing this style for papers and I run into this problem for displaying the authors with the right footnotes. We use the authblk package and thanks command for defining / displaying authors. The ...

1
2 3 4 5
145