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
3
votes
3answers
44 views

Code crashes when inserting a macro into a `\label` and `protecting` the macro doesn't fix

This code crashes because I'm including the macro tmp into the label command. Reading this forum, especially What is the difference between Fragile and Robust commands? , I thought that the \...
0
votes
0answers
32 views

How to reuse argument in macros?

I have the code of the appendix macros: \newcommand{\application}[1]{\refstepcounter{application}% { \par\vspace{\the\baselineskip}\centering{\bfseries\scshape% Приложение \theapplication \par}% ...
7
votes
4answers
438 views

How to test if the product of two numbers are positive as well as finding their absolute values?

I am trying to simplify my work with some latex coding, where the intention is to generate two types of diagrams based on the input. The first type is diagrams with lines only going up and the second ...
2
votes
1answer
18 views

Newcommand with dialogue not working

I m trying to create a new short command for the dialogue package. While the regular use of \speak{} inside the environment works, the \newcommand that I have created using it doesn't. \newcommand*...
1
vote
1answer
43 views

Macro for drawing a right triangle with options for lengths automatically

I am hoping to write a macro so that in the options, I can change the horizontal length and the vertical length to produce an image automatically. I only use the \hordisplay because some of the ...
3
votes
4answers
139 views

How to check what the next character after a macro is

Is there a way to check what the character following a macro is? For instance, suppose I have a command \foo{...} that formats some text, but I want to adjust the spacing if the next character is a ...
0
votes
0answers
31 views

Custom command deletes following character

Since me and others are collaborating on a document, I added a new command which can show who wrote which part. I tried the following and other variations but the same bug keeps on happening \...
2
votes
1answer
37 views

Add to subscript in macro definition

I have the following command \def\pderv#1#2{{#1}_{#2}} which is supposed to denote partial derivatives. In some documents, I sometimes redefine it as the tradional \def\pderv#1#2{\frac{\partial #1}{...
0
votes
1answer
51 views

Selective Text Replacement in Latex

I would like to ask how can I replace selective text in Latex? I am aware of Find and Replace option, but I am looking for a possible way to do as following; Suppose in the following text I have used ...
2
votes
1answer
36 views

How to get TexStudio to recognise user defined math environments

This problem has been bugging me for ages, and I haven't been able to fix it. When writing papers, I like to use \[ \] rather than \begin{equation} \end{equation}. Similarly, for aligned equations, I ...
0
votes
1answer
85 views

Re-defining `\\`

EDIT: The original version of this was a foolish question; @egreg points out that I was thinking of {amsmath}'s matrix environment. I'm sure that this has been asked before, but it's hard to search ...
2
votes
2answers
55 views

Using ifnum with setlength

i need to understand this line of code with details: \ifnum\thetype@box=0\setlength{\spacebottom}{\expandafter\csname spacebottom#1\endcsname}\fi thanks for the help
3
votes
2answers
109 views

Macro techniques using e-TeX

The e-TeX extensions were intended to address some of the shortcomings of Knuth's original TeX, and since they are required by LaTeX2e for a while now, most package authors can rely on their presence. ...
2
votes
1answer
59 views

Newcommand to have easily equations, arrows and comments on the go?

I like the way tikZ combined with beamer can highlight equations (it works well with beamerarticle and article mode as well) as in TeXexample I often use this feature but i think the code is difficult ...
1
vote
1answer
20 views

Redefine \citet command (two optional arguments case)

I need to redefine "\citet" command to have its output printed in red. I did: \let\oldcitet\citet \renewcommand*\citet[2][]{{\color{red}\oldcitet[#1]{#2}}} that works for the "one optional argument" ...
0
votes
1answer
22 views

Storing my 'standard float alignment' in a macro

While writing a few macros to wrap around float environments, I stumbled upon failure of macro-expansion (at least I think so) when it comes to storing float specifiers. main.tex: \documentclass{...
1
vote
1answer
15 views

conditional value in a hyperref textfield

I am trying to create a TextField whose value is conditional on a boolean. If the boolean is true, the default value in the TextField is some value; if it is false, the TextField starts blank (the ...
1
vote
2answers
33 views

command which creates a variable number of spaces

Basically my problem is that I want to treat the argument to a command as a number (and perform arithmetic operations on it), but I can only get it to be treated as a string. In particular, I want my ...
0
votes
0answers
27 views

custom environment that applies a command to every line inside

I'm trying to make an environment which indents every line inside a certain amount, and which inserts newlines in between lines automatically. As of right now, I have a command which does this but I ...
0
votes
0answers
20 views

“import” all my packages and custom commands into a new file automatically [duplicate]

I am new to latex, so apologies if this is a trivial question. I have amassed many useful packages and custom commands and start each document by copy/pasting all of them above "\begin{document}". Is ...
1
vote
1answer
28 views

latex commands (italic and centring ) custom command

I want to ask your assistance in two commands(in latex .tex enviroment) thie first one needs a command which is called redbold, in this command I need form the text red colour and bold style. In the ...
0
votes
0answers
36 views

Renew command with argument into command without argument

Recently I saw someone using \be ... \ee instead of \begin{equation} ... \end{equation} which seems like a nice compact notation to use and I would like to add it to my own template. ...
2
votes
2answers
57 views

Defining Reusable and Easily Editable Keywords

I am writing a paper in which I still haven't made all the stylistic choices. That is I haven't decided which long words I want to abbreviate and how I want to abbreviate them, if the author of the ...
1
vote
1answer
41 views

How to safely I check if a command/package is available at compilation time?

I want to produce a latex document that can compile with very few packages, let's say xcolor might be missing as an example (assume it is a document my bosses will compile and I do not control which ...
0
votes
1answer
26 views

Changing standard \ac Acro package behavior when in section, subsection and subsubsections to default to \acl*

I want to change how the acro package behaves when used in section headers to default to the long form of the acronym and ignore the use of the acronym, equivalent to \acl*{GPS}. I want to do this by ...
2
votes
1answer
35 views

macros/commands inside a filecontents* environment does not expand

i would like to seek your help on the following. Consider the following MWE1: \documentclass{article} \usepackage{filecontents} \begin{document} Hi \begin{filecontents*}{dummy.tex} some text and ...
0
votes
2answers
32 views

Adjust caption of algorithm2e using own macro

I have a document with a few tables that have their captions formatted like this which I achieved using \usepackage[format=plain, justification=raggedright,singlelinecheck=true]{caption} \...
1
vote
1answer
19 views

Why can't I use hyperref and \C together?

Today, I updated from TeXLive 2015 to TeXLive 2019 (about time, right?). However, I am having an issue that I haven't encountered before. I usually declare \C as a macro for the complex numbers. ...
6
votes
4answers
332 views

Appending a character to a token list using its charcode

Is there any way to obtain the actual character token from its character code representation? In particular, I would like to have a macro \prepend#1#2 that takes a token list #1 and prepends the ...
2
votes
1answer
60 views

“File not found” When using command instead of plain text

Good Day, I am trying to find an efficient method to acces files in a remote folder. I have defined several commands for the paths. Line 6 of the below code works and includes the correct file, ...
0
votes
0answers
26 views

Space inserted before and after custom command

I created a custom command to be used for printing sizes. For easier checking the commands options I use a custom 'switch' environment. Sadly there is always a space before and after the inserted ...
0
votes
2answers
37 views

How to keep all comments in new latex file made by newwrite command?

\documentclass[12pt,a4paper,oneside]{book} \begin{document} \newwrite\copyfile \immediate\openout\copyfile=Theorem.tex \immediate\write\copyfile{hello %this is comment 1 ...
2
votes
3answers
49 views

newcommand: cannot include macro as argument

I feel a bit stupid, but I why can't I put macros inside the argument of my newcommand? And why can't my macro \pra work inside the align environment, while it definitely works if I just write ...
0
votes
2answers
51 views

Renewing table of contents distances breaks boldface for page numbers of sections and of titles

It seems like a simple problem but it is not clear how to fix it. Consider this \renewcommand{\thesection}{\arabic{section} ABCXYZ} ... \tableofcontents \section{The title of the section} will ...
0
votes
0answers
31 views

How to redefine \alpha as a command that takes parameters in Latex? [duplicate]

So, I've been trying to renewcommand \alpha by assigning it parameters in Latex. This is what I have for my preamble and the body...(seen below). On line 12, I attempted to create such a "function", ...
2
votes
2answers
31 views

Scaling components in CircuiTikz with necommand

My question refers to: Scaling components in CircuiTikz I would like to scale single circuitikz components to various sizes, e.g. with the command /tikz/circuitikz/bipoles/length=1cm Is it ...
12
votes
5answers
687 views

“Clever tricks” for using \outer macros

From TeX by Topic, p. 111: For certain applications, however, it is inconvenient that some of the plain macros are outer, in particular macros such as \newskip. One remedy is to redefine them, ...
1
vote
2answers
26 views

Editing Cref for custom environments

I recently used Roelof's answer from list the cases in text and I would like to be able to use label Cref to call the different Cases. The environment is \newcounter{casenum} \newenvironment{caseof}...
0
votes
1answer
27 views

How to add extra vertical space behind an equation in the equation environment in latex?

I would like to make a new environment, that would add extra vertical spacing like this (to not have to write \vspace command over and over again): \begin{equation} some equation \end{equation} \...
0
votes
1answer
12 views

Text over arrow using the mathabx package

I switched to the mathabx package and now the command \xrightarrow does not work anymore. What's the way to have text over arrows in mathabx?
0
votes
1answer
57 views

New command for double coset

I defined a new command \doublefaktor to print a double coset of type A\B/C (similar to \faktor which print a quotient A/B) as follows: \newcommand{\doublefaktor}[3]{ {\textstyle #1}\mkern-8mu\...
0
votes
2answers
47 views

Listofsymbols errors when using cascaded formulas

I want to use the listofsymbols package for a nomenclature and the basics seem to work fine. I am able to define symbols and call them by their respective commands. Theere are two errors arising. ...
2
votes
1answer
50 views

How to create an alias of Cyrillic character with leading backslash?

RUN: xelatex book.tex \documentclass[a5paper,12pt]{book} \usepackage[X2,T2A,OT2]{fontenc} \usepackage[english,russian]{babel} \usepackage{marvosym} \usepackage{fontspec} \usepackage{xunicode,xltxtra,...
4
votes
2answers
250 views

Variable as input for command

I want to highlight a specific author in a bibliography and have working code based on the answer given here: https://tex.stackexchange.com/a/73246. I am using biber and have chosen to use the name ...
0
votes
2answers
50 views

Predefined and stable arguments for \NewDocumentCommand

I programed a \NewDocumentCommand which produces vertical bars for each of which the numeric value and label text are mandatory and color as optional argument. There are also some global parameter (\...
2
votes
2answers
68 views

Is there a way to use < and > as delimiters to optional command or environment parameters?

Say I want to define an environment like "color description" which would be the same as "description" except that one could add an optional color background to the label: \begin{colordescription}[red] ...
0
votes
1answer
34 views

Optional argument in \newcommand with subscript and superscript

I want to define a macro with an optional argument that will work with superscript and subscript in math mode. e.g. \binaryB{\alpha} will result into \mathbb{B}^{\alpha}() and \binaryB will result ...
0
votes
1answer
60 views

LaTeX Tikz: Compare two \def arguments

I am writing a macro definition that draws dimensions in the style of technical drawing. I need to perform an inequality of two of the arguments to know which is coordinate is higher up, but the ...
5
votes
2answers
193 views

Macro argument expansion and edef

I created a macro to recognize between two patterns #1 - #2 or #1 - #2 - #3 and assure an output on the form # - # - # (for dates). \def\cal@ymd#1:#2:#3:{#1-#2-#3} \def\cal@md#1:#2:#3:{\cal@Year-#...
0
votes
1answer
26 views

\if\subject\subjectold returns false even though subject and subjectold should be the same

I am currently working with conditionals and I am currently stuck because even though the conditional argument should not be used (e.g. \subject should be "B", \subjectold and \bio too), the test ...

1
2 3 4 5
126