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.

2
votes
4answers
128 views

A command with a variable number of arguments: comma versus and

I have the following command: \newcommand{triangles}[2]{triangles $\triangle #1$ and $\triangle #2}, such that \triangles{ABC}{DEF} produces triangles $\triangle ABC$ and $\triangle DEF$. I would like ...
1
vote
0answers
29 views

`\show` for macro arguments

For debugging purposes, I want to write to the log what is actually passed to a macro as argument. A naive \newcommand\test[1]{\show#1} obviously doesn't do the job. So how can I printout a list of ...
1
vote
1answer
88 views

How to add to FASTEX on Windows?

I have just downloaded the FasTeX package of macros for LaTeX. It is excellent and is already speeding up my work.Briefly, it has a whole bunch of short text strings which, when followed by two space ...
3
votes
1answer
63 views

Renew command \> to \rangle

I would like to use the following commands (in order to simplify writing): \newcommand{\<}{\langle} \renewcommand{\>}{\rangle} Would there be any dangerous consequences of this? I know that by ...
1
vote
1answer
44 views

How can I cancel Math-mode, which is inside a function, from the outside?

So the problem is simple. A function takes something and puts it inside math-mode ($$). Can I influence that from the outside? Example: \documentclass{article} \def\mathmod#1{$#1$} \begin{document} ...
10
votes
6answers
1k views

How can I replace every global instance of “x[2]” with “x_2”

Thanks to Bruno for suggesting that for my specific case, where my results come from Mathematica, it's simply much easier to change the output in there using trivial replacement rules. However, this ...
6
votes
2answers
399 views

Star/Wye electrical connection math symbol

I am writing lots of mathematics within electrical engineering, where I often need to specify which of two connection types I am talking about. One is called Delta, specified with a triangle $\Delta$...
2
votes
1answer
47 views

How to make custom definition command without numbering?

I have the following \definition command/theorem (I don't really know much about LaTeX): \newtheoremstyle{definition} {0.8cm} {0.8cm} {} {0.4cm} {\bfseries} {.} {0.4cm} {} \...
0
votes
1answer
34 views

Adding TeX code as a macro in LyX

I am using LyX and I tried adding a macro that includes TeX code but it seems as if it doesn't recognize the \abs command: To be clarified, when adding the following TeX code the file compiles: and ...
2
votes
2answers
42 views

LaTeX 2e's verbatim-environment and different input-encodings

The inputenc-package provides means for selecting an input-encoding for subsequent tex-input. If I understand correctly, the verbatim-environment as of the LaTeX 2ε-kernel does change ...
2
votes
0answers
33 views

Help Understanding/Adapting the Definition of Beamer's 'lecture' Command

Beamer's 'lecture' command has been a great way for me to have all my lecture notes in one document, but typeset only the segments that I need for any given day/week of class. Ultimately I would like ...
13
votes
1answer
135 views

Understanding LaTeX 2e's \@esphack

I'm reading source2e.pdf and I have problems in understanding the sense of the definition of LaTeX 2ε's \@esphack: Commands like \label{...} , which themselves do not/shall not produce ...
0
votes
1answer
41 views

How much negative space needed? To recognizably remove a space by letting something be added? For macros whose argument is another macro?

Suppose that one has brea + (notice the space at the end). brea + is not printed yet. A macro \m{brea +} will replace + with \added ... how then does one define added, imagine it prints a d but only ...
2
votes
2answers
74 views

Is there a way to convert \def macro in \newcommand macro automatically?

I have a big file of macros, they are all in this form : \def\eclaire{\mathbb} \def\R{\ensuremath{\eclaire R}} I want to have them in \newcommand form, for those macro it's quite easy, i just have ...
4
votes
3answers
161 views

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

What is a good way to write a definition of the type \fun below \fun{abc1 EDF1 xyz1 efg jkl abc2 EDF2 xyz2 efg jkl abc3 EDF3 xyz3 efg jkl abc4 EDF2 xyz4 ...} where the number of arguments is not ...
0
votes
0answers
19 views

Where to put my file of personal macros (TeXShop) [duplicate]

I just got a new MacBook and downloaded TeXShop, and I have a file full of macros and stuff I want to put in the place where TeXShop looks for it so I can input it into every document without having a ...
0
votes
1answer
27 views

Renewcommand within an environment doesn't persist

I'd like to be able to change the behavior of my environment commands by another command. They should be changed until the end of the environment. This is what I thought would happen if I made a ...
1
vote
1answer
34 views

How to make tikz macro work with two arguments in this MWE?

I want to generate a table from a csv file using the very helpful tool datatool and insert a round photo of each person surrounded by a circle, the color of which should be taken from the provided csv ...
2
votes
1answer
16 views

Substitute a space to a string to force tabular cell separation

I'd like to construct tables using macros to align syllables with other text. For that task, I defined a table with no separation between columns. This, however led to words being stuck together if ...
1
vote
1answer
40 views

Wrap every cell on a row with command

I'd like to construct tables with some macros. I have created an environment with a variable amount of columns. One of the macros is supposed to create a row of entries that have no vertical lines. I'...
1
vote
0answers
18 views

Merging lyx files involving different (perhaps intersecting) macros

I want to merge two files written in LyX by my colleague and me. The problem is both of us use self-written macros for writing things shortly. We want to merge our files, and use a chapter my ...
5
votes
4answers
730 views

How to robustly store bits of text for later use

I'm trying to write myself a package, similar to the exercise package, so I can prepare problem sets for my students. I wish to delay the output of problems and/or solutions until a suitable place in ...
1
vote
1answer
50 views

Get a typesetted output of a macro back as a replacement text for another macro

Let suppose you have a recursive TeX macro \formula (with inner control sequences advancing local counters), which once expanded and typsetted outputs an expression that meets all your needs: for ...
0
votes
1answer
34 views

Newcommand that uncludes a foreach with unknown number of parameters

Sorry, but part of the code is in French. However, it won't matter because it's only the listed text I currently have a new command named \listerfe that, combined with \listerfenextarg and \...
4
votes
2answers
62 views

How to evaluate an expression and use the result in newcommand?

I am trying to declare a newcommand \newcommand{\seq}[3]{#1_#2, #1_{#2 + 1} \cdots ,#1_#3} What I want is basically to print the sequence $v_0, v_1, \cdots, v_N$ by calling \seq{v}{0}{N} but it is ...
1
vote
2answers
76 views

Setting superscript for custom symbol

How do I set a superscript for my custom symbol generated with \newcommand*\mysymbol{\includegraphics{mysymbol.eps}}? Default superscripts appear way too far right from the place they should be in. ...
5
votes
2answers
134 views

\newcommand: Combine (optional) star and optional parameter

How may I define a new command that admits starred and non-starred variants, and that also admits an optional argument? I tried the following: \documentclass{minimal} \makeatletter \newcommand\...
0
votes
0answers
33 views

Outputting a custom glossary to a separate file

I'm working on the translation of a German book and have created the following macro so as to link some translated words and expressions to their original, which then I print at the end of the ...
2
votes
3answers
55 views

How do you pass the result of a command as an argument for a command?

I'd like to generate a string and save it for later use. However, it saves the command instead of the string in the following situation: \newcounter{Counter} \newcommand{\ParentNode} {NULL} \...
2
votes
2answers
129 views

Detecting subscript in command argument

I have defined a command low that adds a subscript to an argument: \newcommand{\low}[1]{{#1}_{l_{\mathcal{A}}}} However, if the argument of low contains subscripts itsself (for example in the case ...
0
votes
0answers
35 views

Shortcut for \begin{equation} - recognized as math by Texmaker

When typing a math report, I want to use my prof's advices: he defines shortcut for equations: \newcommand{\be}{\begin{equation}} \newcommand{\ee}{\end{equation}} This makes it much easier to use, ...
0
votes
1answer
40 views

How to color specific word in a paragraph more times?

Maybe the title is a bit misleading and it's my pilot post on here :) Anyhow, I have a paragraph with ,let's say 100 words, from which 10 of those words are word "dokument". I have to make a command ...
1
vote
2answers
63 views

How to correct the following newcommand?

I am declaring a newcommand as follows: \newcommand{\code}[2]{ \begin{listing}[ht] \begin{minted} [ framesep=2mm, baselinestretch=1.2, bgcolor=blue!30!white, fontsize=\footnotesize, ] {#1} #2 \end{...
0
votes
0answers
39 views

Preprocess a .tex file and save it as a new file

I have several .tex files that I would like to share with other people. I've included in them (with the command \input) several files with macros that I've written myself. However, I would like to ...
4
votes
2answers
60 views

How to use correctly \dl with vectors using the diffcoeff package?

I am showing the following question about the use of differential \dl in section six of the user guide diffcoeff. Why does not the command\dl \vec{x} work? When dealing with the unknown x, the ...
2
votes
2answers
76 views

Define cover colors based on current month

I am writing a style guide documentation and I want to make visually appealing what the document was updated using the cover color. The main idea is to automatically update cover color based on the ...
1
vote
1answer
43 views

Stretching table

I defined a custom command to produce a table I have to do for various experiments: \newcommand{\exptable}[3]{ \begin{center} \renewcommand{\arraystretch}{1.5} \begin{tabular}{ccc} \...
0
votes
1answer
114 views

LaTeX with markdown and tables

I'm trying to build up a new documentation system using Markdown and LaTeX. After several hours most things are running smooth, but tables are a bit complicated. Most of the text can be written with ...
9
votes
3answers
248 views

\newcommand: Using one parameter as the default for the other

I would like to define a macro that takes two arguments, one of which is optional. If it is not given, then it should take the other one as default value. Unfortunately, \newcommand{\mycommand}[2][#...
1
vote
3answers
53 views

Using \StrSubstitute in a macro definition

I would like to create a macro that typesets the argument using \emph and also creates a label with that name. My names contain underscores so I tried to use \StrSubstitute from the xstring package: \...
2
votes
2answers
256 views

How do you write a macro that takes arguments containing paragraphs?

I'm trying to write a macro that takes arguments containing paragraphs. If you write a normal macro and one of its arguments contains a paragraph, it will break: \documentclass{article} \usepackage[...
0
votes
1answer
82 views

Use variables like #1 in math [closed]

I'm writing this small \newcommand, and I want to send numbers as parameters. But since the math mode always tries to interpret the # in a different way. I don't know what to do. Here is what I have ...
1
vote
1answer
61 views

help: looking for a generic (and elegant) array (variable) map syntax to keep stuff

My apologies if this has been discussed elsewhere, but if it was I couldn't find it. I am the author of a template for academic thesis for my university, but I'm definitely not a TeX expert. In this ...
2
votes
2answers
59 views

How to cumulate texts at the end into various groups?

Please help: I am editing a .tex file (memoir class) with lot of text, and I want to collect sentences like important questions, quotes, words, etc and collect them into their respective groups and be ...
0
votes
1answer
47 views

Expansion of macro in environment argument

I'd like to generate an environment that changes a bit according to an argument given for it. The reason is having different locales in the document. I have defined a command, EmitLanguageStr that ...
1
vote
1answer
47 views

Generalising a second-order macro with loops

I'd like to construct a macro that can be used to define commands. Those commands behave like variables or structs of variables, such that they can contain multiple values. The "member" is passed via ...
3
votes
3answers
327 views

How to define a macro with multiple optional parameters?

After I had a macro that worked, I tried to improve it by making some parameters optional. Unfortunately the macro no longer works. Instead I'm getting errors I do not understand, for example: LaTeX ...
1
vote
1answer
133 views

What is “# Notation”? How does the # syntax work?

Closely Related: How to implement \expandbefore, similarly to \expandafter? In the related question, a reference is made to the "# Notation". How does the syntax work? From an answer on the other ...
3
votes
2answers
146 views

How to implement \expandbefore, similarly to \expandafter?

I am trying to define a new command, but specifying the new control string "on the fly" using csname and endcsname. (This is for the purpose of implementing a dependency injection pattern.) **...
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 ...