{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.

learn more… | top users | synonyms (4)

1
vote
0answers
23 views

Define new command using \DeclareTotalTCBox in tcolorbox package

I have defined a command using \DeclareTotalTCBox command in tcolorbox package as blew: \documentclass{article} \usepackage[most]{tcolorbox} \DeclareTotalTCBox{\myverb}{ O{red} v O{} } { ...
6
votes
5answers
2k views

Wrapping code (listings, verbatim, or other method) inside a newcommand

For some teaching I've been doing, I'd like to have code from two different languages side-by-side. To do so, I hacked together a newcommand which uses a tabular environment to arrange two verb ...
1
vote
0answers
72 views

Writing modular classes

As an OOP programmer, I am very attracted to the idea of making separate files for independent features within a class definition, where each feature I feel is too long to be included inline in the ...
8
votes
1answer
123 views

Testing for “emptiness”

Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g. \def\foo{% This is... \ifx\baz\@empty Sparta! \else a pony farm. \fi } I am interested in how the ...
3
votes
3answers
203 views

Amplifying fractions

I want to make myself a math portofolio (as a quick reference) and I have a part where I have to 'amplify' a fraction like here: But I don't know how can I do this thing, can you help me? Thank ...
1
vote
2answers
72 views

Expl3: Constructing command sequences from macro arguments

In my LaTeX laboratory I am doing weird experiments with expl3 (just started to use it some days ago, so regarding l3 I am complete newbie) I am trying to generate command sequence within of another ...
2
votes
1answer
80 views

How can branch if I'm in a halign or not?

Edit: It seems that I can use \noalign\bgroup before the \halign. That's fine. But how do I test that I'm inside the halign group? I'm able to write an own if, but it would be better to ask tex for ...
4
votes
1answer
75 views

Can you interpret macro parameters as verbatim?

Basically I want to define a macro whose parameter should be treated as a "script", meaning that I want to print it in a verbatim way including line breaks and special characters. Furthermore, I want ...
1
vote
0answers
39 views

how to expand some macros in latex file [duplicate]

I have a latex file that uses some of my own macros (a mix of tex & latex macros). I need to post the latex source, but don't want to expose the macros (some of which are nasty hacks that just get ...
2
votes
1answer
62 views

Can a command be defined to have key=value in it?

I am learning about making LaTeX commands. I thought that they were just macro, and the command is replaced literally by its definition. But the following example does not work and I wanted to ask if ...
3
votes
1answer
74 views

Items from file in itemize enviroment

Is it possible to import items from a file into an itemize environment? For example, consider a file with just words and no formatting: Elem1 Elem2 Elem3 Elem4 ... Elem120933 I like to read in this ...
5
votes
1answer
41 views

Define nested sections in a relative way

When working with large tex documents I often find myself using search/replace to restructure them (eg. make sections out of chapters or subsubsections out of subsections) Is there any way to define ...
19
votes
2answers
3k views

How do I use \show?

Q: How do I use \show to determine macro definitions?. I've followed advice here: The definitions of LaTeX commands and here: \show with fewer lines? and am still struggling. I've naively tried ...
17
votes
1answer
4k views

Comparing an argument to a string when argument is a result of a command with etoolbox

I've got an example like that: \documentclass{article} \usepackage{etoolbox} \newcommand{\ab}{a} \newcommand{\aORb}[1]{% \ifstrequal{#1}{a}{"a" was given}{not a}, % ...
7
votes
1answer
119 views

How can I iterate over a newline-delimited text file?

Would I need to use a token list? For the purpose of removing confusion, let there be two delimiters: input delimiter (what LaTeX reads as input) output delimiter (what is seen on paper) I would ...
2
votes
2answers
149 views

how to define newcommand that takes []{} as arguments and not {}{}?

I find myself doing a lot of things like this below in order to compile document for both pdf and tex4ht \ifdefined\HCode \includegraphics[width=0.5\paperwidth]{foo.eps} \else ...
2
votes
1answer
111 views

Add index item by macro

I am struggling with creating a macro that would enable me to create index items by macro. From a former post (LaTeX: is it possible to create a macro to add words to index (using TexMaker)?) I have ...
2
votes
1answer
59 views

etoolbox package explanation requested

I am trying to understand the following package etoolbox. I am unsure about the meaning of the following syntax since I am not sure what is the correct question to ask in google or in the book of ...
7
votes
4answers
134 views

Detect if a macro argument is only one symbol

I define a bunch of functions (or operators, if you like) using a little helper \parens, which adds parens on demand: \newcommand{\parens}[1]{ \ifthenelse{\equal{#1}{}}{}{(#1)} } ...
4
votes
2answers
39 views

Problem with gb4e and macro for tabular with curly brackets

When using the macro \CurlyBrackets at the beginning of a gb4e example, the example is not typeset as expected. Is there a better way to do this to get the desired output? MWE ...
5
votes
3answers
97 views

Check occurrence of a macro inside another macro

With the substr (or xstring) package you can, of course, identify whether a control sequence contains some text string: \documentclass{article} \usepackage{substr} \def\somecontrolseq{some silly ...
4
votes
0answers
46 views

What does `\escapechar` do? [duplicate]

In latex.ltx you can find several situations where \escapechar is set to -1 -- from what it's clear that it has to be a count register. But, what does it actually "count" or control? A small ...
1
vote
1answer
43 views

Next word macro inside braces

I have defined a macro that highlights the next word using \def!##1 {\hkw{##1} }% where in this scope, ! is an active character. So it works fine to write. \emph{This is a !good example} but not ...
2
votes
1answer
128 views

Using command parameters to use another command

Say I have written two commands, CommandA and CommandB. I wish to have a third command that takes inputs to determines which of the two previous commands to execute. Very naively this how I would try ...
1
vote
1answer
68 views

Argument until non-alphanumeric character

Not sure if this is possible or not... I would like to turn (say) + into a command with one argument without braces. This argument should be everything following the + up until the first ...
5
votes
2answers
65 views

Creating a \newcommand for a tikz diagram

The document I'm writing is full of diagrams of arrows, therefore I'd like to create a newcommand \diagram that avoids me to write every time the settings of the tikzpictures. I put ...
7
votes
1answer
233 views

plus/minus vs +/- in latex preamble

In the following code, I need to use +/- where I have used it, and plus/minus where I have used it. \documentclass{amsart} \usepackage{lipsum} \usepackage{calc} \parindent=0 pt \parskip=12 pt plus 0 ...
4
votes
0answers
52 views

Strings and memory usage

The TeX engine was originally written in Pascal before dynamic memory allocation was generally available. Modern implementations tend to be done in C. To qualify as TeX an implementation has to pass a ...
26
votes
5answers
3k views

Macro for \left( and \right)

I know there has been discussion about this topic, but I haven't seen a working solution. Is it possible to define a macro within LaTeX, such that inside math mode, ( would produce \left( and ) would ...
2
votes
1answer
31 views

Shortcut/macro for surrounding words with brackets

When using BibTeX I usually need to fix broken capitalization by surrounding words with brackets (as answered in BibTeX loses capitals when creating .bbl file). I also use this to fix some issues ...
2
votes
2answers
60 views

list environment where some items don't start new paragraph

I want to use a list-like environment, but I need to put some short items on the same line. The user interface will be something like: \begin{enumerate} \item First very long element \item* shrot ...
2
votes
2answers
67 views

Some questions about making scalar product in latex

I've just got registered here but I always read the site and I haven't found the answer for the following question. I just wanna make a specific view for scalar product. It should look like: . I use ...
7
votes
5answers
386 views

Command to count characters in a specified string

Is there a way to count the number of characters in a specified string? Suppose I had the following code. \documentclass{article} \newcommand{\numchars}[1]{\noindent The string ``#1" has ? ...
3
votes
2answers
82 views

Latex dynamically named macro doesn't work

In this MWE, \Nba is not created. How to have it ? Edit Remplacing \newcommand by \gdef makes \Nba exist but gives fantaisist value ? Any idea ? \documentclass[10pt,a4paper,french]{article} ...
5
votes
1answer
51 views

Rewrite \begin{foo}\end{foo} to \begin{bar}{opts}\end{bar}?

I know this is likely a simple Latex macro question. I've got a large document with a ton of lstlisting blocks, and I'd like to use minted instead. That means turning blocks that look like this: ...
0
votes
1answer
57 views

Command to automatically start new row

I need not trivial help. I have a command with parameters. This command fills in and prints the following table: \begin{longtable}{|p{3.2cm}|p{2.5cm}|p{2.5cm}|p{2.3cm}|} \hline Some Text: & ...
2
votes
0answers
104 views

Create all queries in separate file like \listoffigure

I would like to print all the queries collect from the article and need to print in article opener page. How do achieve this? My MWE: \documentclass{threecolumn} \begin{document} \jnltype{37} ...
10
votes
0answers
109 views

Determine File Name and Line Number Where a Macro is Invoked From

Wondering if there is any way to print out (for debugging purposes) the file name and the line number from where a macro is invoked (not where it is defined). My attempt to use the currfile package ...
16
votes
2answers
567 views

Writing musical pitches

Is there a package or macro that allows me to easily typeset musical pitches, like the following: ? Indeed I would like to have subscripts for the octaves. Let's say $\mathrm{E}\flat_3$ How ...
2
votes
2answers
47 views

Gobbling punctuation if command has no optional argument

I want to define a new macro that gets an optional argument X and a citation key Y. If only Y is present it prints \cite{Y} If, however, also X is present it prints X, \cite{Y} This ...
4
votes
1answer
47 views

how to delete the space if argument is empty

I made a \newcommand for my glossed examples using ExPex package, that looks like this : \newcommand{\exgl}[6]{\ex\label{#1}\begingl\glpreamble \tt #2// \gla #3// \glb #4// \glft #5 // \endgl ...
5
votes
2answers
57 views

Where is \@makefntext defined?

I was studying how footnotes come about in LaTeX and what processes exactly run behind the curtain, and noticed \@makefntext. But in fact, in latex.ltx there are only two occurences of this macro ...
4
votes
0answers
27 views

standalone package and user-defined macros/lengths

This is my first post on this amazing website, so hi to everybody!! I'd like to know if there is a way to pass some parametrs (macros or lengths) to a standalone file. Here is my MWE: Consider the ...
1
vote
3answers
66 views

How to unstyle styled macro in headings?

I have a macro that occurs very frequently in the text. At one occasion, it occurs inside a heading, which causes some problems: \documentclass{scrartcl} ...
0
votes
0answers
31 views

How can I recognize a dot followed by a space and output dot?

In the following code I cannot figure out what to use for \SPACE and \DOT such that \peektoken is compared to a space( ) and a dot(.) is produced as output along with the result of the test T(rue) or ...
3
votes
1answer
38 views

A command for table entry by columns

This question is in followup to this question; an excellent response there has allowed me to very easily make tables for examples in the grammar book I am working on which have one language on one ...
4
votes
2answers
161 views

Simple calculation inside \def command

I would like to define a command that does some simple calculation, like this: \def\rectangle(#1,#2)(#3,#4)#5{ \psframe(#1,#2)(#3,#4) \rput((#1+#3)/2,(#2+#4)/2){#5} } % ...
3
votes
1answer
101 views

How to recognize double spaces and give meaning to them?

I'd like to recognize two space characters and give my own meaning to it. Why does this not work and how can I fix it? {\catcode`\ =13%make space active ...
15
votes
1answer
243 views

LaTeX programming Inheritance with \newcommand \newenvironment \renew… etc

I'd like to create (or renew) several LaTeX commands and environments, and understand how it works. One of my new environments would be equivalent to \begin{quotation}. So, imagine my \begin{foo} ...
4
votes
1answer
79 views

Macro for creating a table

I want to have a macro that creates tables of a specific type which specialize in multiple choices questions. The required command \createtable{#1}{#2}{#3} has three arguments: The total number of ...