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
1 answer
2k views

Set builder notation command, adjusting mid bar

I would like to create a command which prints its arguments in a set builder notation. The problem \documentclass{article} \newcommand{\set}[2]{\left\{\ #1 \ \left| \ #2 \ \right. \right\} } \...
0 votes
0 answers
57 views

using a variable in two tex documents

I have a file named "main" and other name "other" and I want input data in main file and these data will be processed by external, for example: file main.tex \documentclass{report} \def\name#1 \...
5 votes
1 answer
146 views

Why does this macro break with Lastpage?

I have made a macro \@Romankern that makes roman numerals with a negative kerning between them to make them closer to each other. I named it \@Romankern to allow it to be used with \pagenumbering. ...
19 votes
2 answers
4k views

Trimming whitespace around text (like LTRIM, RTRIM and TRIM)

When working in Excel with text strings, it is convenient to use the LTRIM, RTRIM and TRIM functions which removes white space around text string. What would be an efficient way of duplicating this in ...
2 votes
1 answer
476 views

Exam class: Macro for computing subtotal marks

I have a question (code given below) which has subparts. Part (a) is further divided into 3 parts: i, ii and iii, whereas Part (b) does not contain any subparts. The total points awarded to this ...
1 vote
0 answers
249 views

Hide commands, show text only [closed]

Is there a way in TeXstudio, or any other editor, to hide all tags and commands and just show the text? I would need to translate a .tex file, text is already translated, now I have to bring it back ...
5 votes
2 answers
876 views

Creating ethane using \chemfig

I was tinkering with chemfig package. I created the macros \documentclass{article} \newcommand{\lmethyl}{C(-[2]H)(-[4]H)(-[6]H)} \newcommand{\rmethyl}{C(-[2]H)(-[6]H)-H} \newcommand{\tmethyl}{C(-[2]...
0 votes
0 answers
54 views

Relaxing a command's requirement to be run in mathmode (specifically \sage in tikz \draw command)

I would like to be able to build a dynamic tikz picture using some random numbers generated via sage. Presently this seems to fail because tikz doesn't like the mathmode that sage has to be run inside ...
21 votes
3 answers
10k views

Special behavior if optional argument is not passed

I am looking to define a command (actually, an environment, but that shouldn't matter for the purposes of this question) that does some default behavior, and if an optional argument is passed, does ...
0 votes
1 answer
403 views

New environment using tasks

I'm trying to create a new environment: \newenvironment{tasksx}{ \begin{tasks}[counter-format = (tsk[a]), after-item-skip = -.5ex, before-skip = -2.5em, after-skip = 1em] \task \end{...
0 votes
1 answer
270 views

What is the command of double parentheses in Latex? [duplicate]

What is the command of . in Latex? Thanks!
0 votes
0 answers
488 views

Conditional to execute alternative code when error detected

I would like to be able to build a conditional to execute one set of code if the conditional would compile, versus another if the code would generate an error. Take the following code block which ...
5 votes
1 answer
186 views

How to make a math mode non-Ord macro?

I want to make a new macro that'll act like its own character. Specifically, I want \macro to expand to a\kern0.5em b, but still act as a Rel character (i.e. 1\macro1 would have a small space around ...
2 votes
2 answers
3k views

Efficiently Passing Multiple Arguments into a \newcommand

Suppose I define a \newcommand with multiple arguments, such as in this example: \documentclass{article} \newcommand{\testing}[9]{#1,\ #2,\ #3,\ #4,\ #5,\ #6,\ #7,\ #8,\ #9} \begin{document} \title{...
2 votes
1 answer
939 views

Reading and (custom) formatting a CSV (not \csvautotabular)

Suppose I have a really long, really boring list of data in - let's say CSV, but converting to other formats is an option, when this can be done automatically - and I want to prepare a section in my ...
6 votes
3 answers
4k views

Passing an array type argument for new command

I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following: \newcommand{\loopy}[1]{ \begin{tikzpicture} \foreach ...
1 vote
1 answer
56 views

LaTex sequentially numbered footnotes even if empty content

I'm trying to accomplish this in LaTeX: I have a text divided by something we can call "versicles", like the Bible (it's not the Bible but it will be easier if you think of it as the Bible), each one ...
1 vote
1 answer
346 views

Shortcut to wrap text with latex macro (macOS, systemwide)

I'm looking for a way to create systemwide shortcuts on macOS to wrap selected text with some LaTeX macro (like {}, or \emph{}, but especially I'm interested in some creating some custom ones). I ...
2 votes
2 answers
581 views

New command without brackets inside new environment

I've made a new environment to do commented lists, an adapted itemize without symbols: \documentclass{report} \usepackage{mathtools} \newenvironment{clist} {\newcommand\com[2][1cm]{\par{\small\...
0 votes
1 answer
52 views

How to make a new command for inserting an inline matrix? [duplicate]

I know I will be doing many calculations with the basis vectors (1,0) and (0,1) so I'm trying to define a command so I can write this vector inline. However, I'm getting the following error: "LaTeX ...
2 votes
2 answers
241 views

How to specify an accent's relative position?

Building on this answer, I created symbols that looks like curly \ll and \gg with a dot on top, as follows. \documentclass{scrartcl} \usepackage[utf8]{inputenc} \DeclareFontFamily{U}{mathb}{\...
8 votes
2 answers
4k views

How to store and restore the current font size?

In relation with this example: New command without brackets inside new environment, I have to pass the current font size to the environment, but I prefer it takes it by itself? To make it clear, I ...
2 votes
2 answers
97 views

PGF macro to map value to a different interval

I'm trying to write a macro to be used with random generators (in particular rnd) within Tikz, to map numbers to different intervals. [0, 1] ---> [a, b] f(x) = x*(b-a) + a What I tried so far is:...
3 votes
2 answers
171 views

Why does this suppress command work when conditionals don't?

I have been exploring different methods of suppressing environment content under some conditionals. The problem with environments is that a lot of the tricks don't work because of how the environment ...
2 votes
1 answer
88 views

Impossible to put some TikZ code in a \def

The following code does not compile. \documentclass{article} \usepackage{amsmath,tikz} \usetikzlibrary{matrix} \begin{document} \def\xxxxx {\begin{tikzpicture}[% from https://tex.stackexchange.com/...
0 votes
1 answer
63 views

If value changes for no apparent reason

I am trying to create a horizontal enumeration environment with 3 items per row. As seen in the example the \ifferstitem conditional seems to turn to TRUE from FALSE for no apparent reason (at least ...
2 votes
3 answers
100 views

Is it possible to create a macro that changes when $\mathrm$ is applied to it?

I would like to define a macro \newcommand{\III}{I\hspace{-0.2em}I\hspace{-0.2em}I} in such a way that when I type $ \mathrm{\III} $ in math-mode, the compiler will compile $ \mathrm{I\hspace{-0....
2 votes
2 answers
1k views

How to return a value from a function in LaTeX3

I have this MWE that tries to return a value from \l_example_foo_int from a function: \documentclass[a4paper]{article} \usepackage{expl3} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\...
0 votes
0 answers
134 views

How to dynamically generate function argument signatures using custom API in LaTeX3

In trying to learn more about the details of what is possible with LaTeX, I wanted to see if I could create an API around creating functions. This is what the output function would be, for example: \...
0 votes
1 answer
92 views

Alternative to defining nested commands in LaTeX3

Since it seems that the LaTeX convention is to use globally scoped instead of locally scoped commands/environments (which makes sense now for a complex reason), I am wondering how to handle the case ...
3 votes
0 answers
116 views

Latex is really just a bunch of Tex macros?

A question of no practical importance, just curious: One reads that Latex is just a collection of Tex macros. Is this literally true? A more precisely specified version of the same question: Does ...
4 votes
2 answers
353 views

A way to "execute" only latex procedural code (\def, \let) in a sequence ignoring the rest?

I have an external input file which I am reading line by line. This file contains text as well as some tex/latex macros. My goal is to write the content of this file into another external output file, ...
1 vote
1 answer
320 views

\let on macro defined by \newcommand with optional argument [duplicate]

Suppose we have \newcommand{\foo}[2][optional]{#1 #2} defined somewhere (e.g. some package) and want to redefine it and re-use the original definition. This usually works with \let like described in ...
10 votes
4 answers
1k views

Conflict between endfloat and figure floats included via macro

I use \newcommand to quickly include figures. But combined with endfloat, it throws an error. Any ideas how to send floats to end when included this way? \documentclass{article} \usepackage{graphicx} ...
1 vote
1 answer
126 views

Line break in macro with > 9 parameters

I have a transition system where the transition requires many arguments to describe it. It ends up looking like this: A \xlongrightarrow[a_1; b_1; c_1]{a_2; b_2; c_2} B So naturally I have a macro ...
2 votes
0 answers
63 views

How to pass in nested expression using pfgkeys

I have a setup with 2 simple macros: \documentclass[a4paper]{article} \usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{pgfkeys} \begin{document} \...
4 votes
1 answer
4k views

Overloading command parameters in LaTeX

Wondering if you can accomplish all of these variations in LaTeX by defining a custom command: \mycmd{tag}{color}{keyval} \mycmd{tag}{keyval} \mycmd{keyval} So it could be used like this: \mycmd{...
8 votes
4 answers
536 views

Check for group as argument (expandable)

I want to check whether an argument of a command is fully contained in a pair of curly braces without using any extra packages. For this I define two macros containing { and } with catcode 12, ...
0 votes
0 answers
57 views

(Framed) environment blank spaces

Could be a very beginner question, but still. Considering the following: \usepackage{framed} \usepackage{tikz} \usepackage{listings} ... \newcommand{\some}{\textcolor{red}{\lstinline{some}}} \...
3 votes
1 answer
79 views

Is there any package where the reference writes the equation?

Just a question for knowledge. I would like to know if there is a package that by doing a label of a equation and referring to it with \eqref of whatever command it is, that equation appears ...
8 votes
2 answers
521 views

Latex custom counters

I have been studying the way that custom enumeration labels work From source2e.pdf I get: \def\alph#1{\expandafter\@alph\csname c@#1\endcsname} \def\@alph#1{ \ifcase#1\or a\or b\or c\or d\or e\...
2 votes
1 answer
53 views

oolatex formatting difficulties with newcommands containing math mode

Compiling this simple example with mk4ht oolatex (which I then headlessly convert to a docx file), I find myself a little confused by the result I get. Note, everything is as expected with the pdf ...
1 vote
1 answer
41 views

Passing additional variables into macro

this is a follow up question from Printing arguments in \newcommand at different parts of document I managed to get the MWE from that question to work from the great help which I have got. I thought ...
4 votes
1 answer
696 views

Printing arguments in \newcommand at different parts of document

I am trying to make a re-useable latex document for setting exam questions together with the answer keys. Because the intended future users will not be familiar with Latex, I have made some templates ...
1 vote
1 answer
72 views

LaTeX output local lists on root document

This is a followup question for this question, where Christian Hupfer provided me a great solution for a certain problem: I wanted to list the occurrences of special commands within a section at the ...
1 vote
1 answer
624 views

Calling package function inside a package function

I am writing a package which currently works okay. I want to use function \makeatletter \def\zz#1{\zzz0#1\relax} \def\zzz#1#2{% \ifx\relax#2 \the\numexpr#1\relax \else \expandafter\zzz\expandafter{%...
4 votes
3 answers
428 views

accumulator variable

I know in latex it is possible to use counters which are based on integers. Is there also some way to define a floating point register to perform simple arithmetic operations? Basically I would need ...
5 votes
1 answer
814 views

How to pass through options to newcommand

I have a command essentially like this: \newcommand\cl[2]{\tikz{\filldraw[fill=#1,...#2] (0,0) circle [radius=0.1cm];}} \begin{tikzpicture}[scale=0.8] \cl{blue}{dotted,minimum size=1mm} \end{...
3 votes
0 answers
3k views

New command without arguments in LaTeX [duplicate]

I'm using the devanagari package to typeset Hindi/Sanskrit alphabet in LaTeX. I have defined commands like \newcommand{\S}{{\dn saa}}, \newcommand{\R}{{\dn re}} etc. From a usage point of view, I ...
5 votes
4 answers
265 views

Unwanted spaces in user defined structures and the uses of % [duplicate]

This question arise from my recent activity on user defined commands of various kind. In the answer to a recently posed question, @egreg pointed out to me the importance of not forgetting a % after ...

1
72 73
74
75 76
165