Stack Exchange Network

Stack Exchange network consists of 174 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
11 views

How to use macro name itself as an argument

I'd like to define a macro in which its name will be used as a logical reference. For example, if the macro name is \mycmdAAA, it typeouts AAA; if the macro name is \mycmdBBB, it typesouts BBB; if ...
2
votes
1answer
9 views

2 Column Table with a list and image

I am trying to create a user manual in latex. I'm trying to use a 2 column table, one column has a list and the other column has a screenshot This is what I'm trying to do I can create a minpage, ...
1
vote
1answer
19 views

Toggling parts on and off

I am composing some notes for a workshop which will have a mixed audience who use different statistical software packages. For the lab sessions, I wish to create a practice that contains questions and ...
0
votes
0answers
18 views

How to input a .lyx file through a .tex macro in LyX

I have a top level .lyx file that I am building with LyX. I have several LaTeX macros in the preamble, one of which is wrapper over the LaTeX \input{} macro. When I try to use this macro in an ERT in ...
2
votes
1answer
36 views

Using a macro with TikZ style attributes in a draw command

For use in a \foreach loop, I would like to have the style attributes for a rectangle stored in a macro. The style attributes would include the fill color, opacity, etcetera (but the attributes that ...
0
votes
2answers
44 views

Error during expanding macro command in preamble

I try to create a command if...else which seems correct when i expand it in body but not in preamble. The package answers seems to be not include because the \Newassociation command is unknown. I try ...
0
votes
0answers
13 views

Creating Commands which Make New Environments [duplicate]

I want to make a command similar in idea to \newtheorem. Specifically, I need to create a command which defines a new environment that takes optional arguments. However, the command also takes in ...
1
vote
0answers
17 views

Writing macros with a large number of arguments [duplicate]

How can I write a macro with more than 10 arguments?
2
votes
2answers
57 views

expand variable inside \input

I need to dynamically input a proper .tex file into my document. I wrote the following code that works only if instead of "\realyear{\season}" I explicitly write 2019. Inside the \input all new ...
0
votes
1answer
21 views

Command with or without parameter

How to define a command \def\hello{Hello world!} that can be called with no parameter: \hello or with a parameter: \hello{3} but that won't be displayed anyway (3 shouldn't be displayed, it's ...
4
votes
4answers
201 views

Draw a shape with operation on parameters in Tikz

I want to draw a shape that I want to reuse. This shape is defined by geometrical input parameters (distances, radii) in a newcommand. Thus I want to perform some operations to define for example the ...
0
votes
0answers
26 views

text wrapover in a tabular in cv template (Michael Decorte's)

In the following, the text wraps over inside a 'body', but not in an 'employer'. Yet, I want to have the text wrap over in 'employer' as well. Any suggestions? The style I am using is res_yy.sty from ...
3
votes
0answers
105 views

Is there a BNF grammar of the LaTeX format?

I know it seems like there is no BNF for TeX language. But I am interested in BNF, PEG or any other kind of formal grammar for the LaTeX format. Is it possible to create such a grammar for pure LaTeX ...
1
vote
1answer
25 views

store parameters of one macro in another macro

I want to create a macro that expands to some parameters to provide to another macro. Here is a very simple example: \documentclass[]{article} \begin{document} \newcommand{\parameters} { {2} {3} } ...
0
votes
1answer
32 views

Protect fragile variable in file path. Case of \ifthenelse in \includegraphics{}

In this script: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\myfigure}[1]{% ...
2
votes
1answer
27 views

using commands in pgfkeys not working

The following latex code works as expected. It allows to draw a line parallel to the z axis: \documentclass[border=10pt]{standalone} \usepackage{tikz} \begin{document} \tikzset{ parallel to z axis/....
0
votes
1answer
28 views

Paragraph indentation after using `\ensuremath`

I have created a macro that writes the progressive number of the exercises in an exam sheet. The macros works in normal mode and in math mode, so that I am able to write something like this: \...
1
vote
1answer
49 views

LuaLaTeX set a path in lua

I have defined a command \newcommand{\mypath}{/Documents/Myfile/additionalresources/} that contains the path to some external files that I need in my main file. I need to use the \mypath command to ...
2
votes
3answers
36 views

Referring to element in a list macro using index

Here is a minimal example of what I want to accomplish: I have defined a list, such as this: \def\listA{1/a/A, 2/b/B, 3/c/C} I am now able to successfully loop through this list using \foreach ...
2
votes
1answer
51 views

What does \bbbn mean?

In a LaTeX document, I found the definition of a structure as {\cal_A}_0 = (bbbn; 0; s; =) (written as literals appearing in the compiled document, not as source code and / or in math mode). What ...
2
votes
2answers
196 views

Check if argument is math expression. The case of making the first letter uppercase

In this example: \documentclass{article} \usepackage{xspace} \newcommand{\pt}{\ensuremath{p_{T}}\xspace} \newcommand{\capitalise}[1]{ % if string ...
1
vote
1answer
29 views

\ifthenelse as an argument to \equal

In this example: \documentclass{article} \usepackage{ifthen} \newcommand{\objtitle}[1]{% ...
1
vote
1answer
21 views

suscpicion of package overshadowing \def command

In the following example: \documentclass{article} \usepackage{amsmath} \usepackage{graphicx} \usepackage{subfig} \def\tag{hello} \newcommand{\createfig}{% ...
2
votes
1answer
37 views

How to protect a fragile command in a moving argument? The case of macro containing \ifthenelse in \caption

This script works as expected: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\foo}[1]{ \newcommand{\capt}{ \ifthenelse{\equal{#1}{ORIG}} {original}...
6
votes
2answers
177 views

Remove backslash from string

I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-...
0
votes
1answer
20 views

Override macro with \renewcommand{} multiple times from different files - toc addcontentsline

Intro While trying to get my head a round my current problem (To add a line to the toc, depending on the comparison of the values of two makros/commands: please see here: Add tocline depending on ...
2
votes
2answers
32 views

Trouble defining multiple optional arguments with \newcommand

Of late I have been troubling and unable to overcome an issue happening, when I want to open and end an environment inside a \newcommand with multiple optional arguments: \documentclass[10pt,a4paper]{...
1
vote
1answer
26 views

\input command recompile error “File ended while scanning use of \@xdblarg.”

Hello i have an annoying problem. Its about the use of \input command I have created a folder called Docs and within that folder i have a folder called cha for chapters. my main file is called ...
2
votes
2answers
39 views

Latex macro lists in \foreach

I have the following code, where I define two separate lists. I want "foreach" to pick items of these two separate lists. This question is updated to make it clear that "AA" and "BB" are also needed ...
3
votes
2answers
81 views

Define an active character inside a definition

\def\test{\catcode`!=\active \def!{test}} Of course the above code would not work because nothing is executed when TeX is reading the replacement text of a macro definition. ! gets catcode 12 anyway....
3
votes
1answer
40 views

Why does the node style newcommand not work in tikz-qtree?

To reuse the labeled node style in tikz-qtree, I have defined \newcommand{\lnode}[3]{\node [label = {#1} : {$#2$}] {#3};}. However, \lnode does not work as in \Tree [.\lnode{above}{[1,5]}{$x$} .... ...
0
votes
0answers
19 views

Use of macros to substitute several characters at once

I'm trying to make a macro in texstudio that allows me to find and replace part of a text with another one, as it is done manually with ctrl + R, using this sentence. editor.replace("{\'{a}}",options,...
3
votes
3answers
39 views

xstring TeX capacity exceeded

I try to store the result of an xstring pagckage’s command in another command (or variable, I don’t care), to reuse it in another xstring’s command, as you can see in the following MWE: \...
2
votes
1answer
53 views

longdiv macro without answers

This code (using longiv) produces \documentclass{article} \input{longdiv} \begin{document} \longdiv{52}{2} \end{document} I'd like to replace the answers with _s. Can anyone suggest the right way ...
0
votes
0answers
31 views

Weird \hfill behavior with custom length calculations?

I asked a question earlier about trying to write a macro/environment that would take in a number of \choice commands and then write them out in a way to minimize vertical space consumed, but still ...
2
votes
1answer
49 views

\newcommand inside a tikz node

In this example \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{shapes.misc, positioning, calc} \newcommand{\element}[1]{[draw, rectangle] {#1}} \usepackage{tikz} \begin{document} \begin{...
4
votes
2answers
161 views

LuaLaTeX: define a macro that stores data to an external file

I would like to implement a macro that allows me to give two arguments and and see this two arguments be saves on an external file ‘data_file.lua’ in a table, something like data[key] = value. ...
0
votes
1answer
45 views

bolding math and text simultaneously for commands

According to this link: Question about bolding math and text simultaneously, using \boldmath{\bfseries{}} simultaneously will make both math and text bold in an equation environment. However, if ...
0
votes
0answers
18 views

Arbitrary Bracing read from input. Mismatched brackets

I am trying to define a function which takes arbitrary bracing in the input. I want the input form to be similar to the \qty() function in the physics package, where \qty(#1) \qty[#1] \qty{#1} will ...
1
vote
1answer
63 views

Replace string in .tex file then compiled by latex

The document is created from different file and included using \input{filename.tex}. In all these file I want to replace a string by a new string but not losing grammar and pulling checking provide by ...
1
vote
1answer
30 views

How to format a generated multiplication table

I can create a multiplication list thought this code, but I have no idea how to format it to be aligned and usable. \documentclass{article} \usepackage{pgffor} \usepackage{pgfmath} \def\sz{11} \...
1
vote
2answers
69 views

Macro to display horizontal even spaced text and math that can go past a single line?

I am trying to write a macro that can take in a grouping of choices, then list them (in a specific, but possibly randomized, order) to use as little vertical space as possible while still presenting ...
4
votes
2answers
75 views

Command with arguments separated by comma

I have created a command that uses 3 arguments, i.e, \newcommand{\mycommand}[3]{% \begin{tabular}{c} #1 \\ #2 \\ #3 \end{tabular} } so, when I use this command I use \...
5
votes
2answers
283 views

LaTeX newcommand limitation

I want to know the possibilities and the limitation of LaTeX's \newcommand regarding the definition and the use/call of new macros. I know some of these examples are primitive but they can help to ...
4
votes
2answers
168 views

Linebreak in centerline

I am using plain TeX. I would like to define a macro \cpar that makes \centerline{A\cpar B} expand to \centerline{A}\centerline{B} I have experiemented with things like \def\cpar{\egroup\...
0
votes
0answers
41 views

Macro redefinition within sectioning titles does not work in ClassicThesis

MWE #1: \documentclass{scrbook} % KOMA-Script book \usepackage[T1]{fontenc} %\usepackage[style=arsclassica, parts=false]{classicthesis} \begin{document} \tableofcontents \def\aaa{a} \...
4
votes
2answers
120 views

Plain LuaTeX: Detecting if displaymath is ended by $$ or \Ustopdisplaymath

In the TeX Book (chapter dirty tricks) there is mentioned a way to left align displaymaths. https://arxiv.org/macros/cp-aa.tex A macro \displaysetup whose argument is delimited by $$ is used. So it ...
4
votes
1answer
27 views

Custom command to lay out a row of images

I'm learning expl3, and to practice I created a simple command to lay out a row of images so that the row fits in one line and all the images have the same height and, optionally, a spacing between ...
6
votes
2answers
310 views

How to make a bracketed environment like this?

I'm hoping to write a custom environment for a double-bracketed "key point" section (see image below). The left and right brackets should be as tall as the text and there should be a little icon with ...
0
votes
0answers
43 views

How to use custom command output as lenght?

In order to convince TeX to keep the grid I tried to program a command, that takes a font size switch as parameter and calculates the reminder of the division of the corresponding baseline skip and ...