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

9
votes
3answers
486 views

How to produce this table in latex?

I want to produce the first two rows of this 5-column table in LaTeX: As you can see it is a special type of tables where we see: itemized lists inside but inconsistently, ie. column 4 all rows ...
17
votes
4answers
497 views

Detect whether running on pdfTeX or Knuth's TeX for conditional include

Does anyone know a way to detect whether one is running in pdfTeX or Knuth's TeX? I want to be able to conditionally include extra features when a document is being built using pdfTex, but also ...
3
votes
1answer
43 views

Newcommand with PythonTex

I want to realize pytontex \pyc as newcommand so that I can use it in a generic way. When I use the newcommand I just get some strange "i" (I use it for enumerating the spec variable) and no output ...
1
vote
0answers
43 views

Problem with microtype's `\textls` and math mode

I have some issues with classicthesis' \spacedlowsmallcaps command that I could bring down to the following MWE: \documentclass{scrartcl} \usepackage{microtype} ...
3
votes
1answer
29 views

unicode-math and redefine a built-in math command

I'm trying to redefine a math command (let's say \int) so that it will always do more (let's say \int lol) using the following trick: http://tex.stackexchange.com/a/47353/15659 BUT, now I want to use ...
4
votes
0answers
26 views

Defining a command where the argument could contain percent signs [duplicate]

This minimal example won't compile: \documentclass{article} \usepackage{url} \newcommand{\mycommand}[1]{#1} \begin{document} \mycommand{\url{http://www.example.org/index.php?a=Hello%20World.}} ...
0
votes
0answers
19 views

Spacing between custom command and subsequent text [duplicate]

I have defined a custom command for the name of my project; e.g. \newcommand{\projectname}{Gizmo}. When I used the command in my document, I've found that I need to place a ~ after the command in ...
4
votes
4answers
149 views

Expandable macro with loops and advanced string functions?

This might be a very basic problem (as a follow-up to this question) but I cannot figure out how to do it: I need a macro \mycmd{sometext} that yields a string depending on the first character of its ...
17
votes
4answers
1k views

Is there a way to eliminate the “\” in frequently used LaTeX commands?

The "\" in all of the commands requires frequent finger gymnastics of the pinky of the right hand in LaTeX, at least for the touch typist. It occurred to me that although it makes things more ...
3
votes
1answer
117 views

Defining #1^#2 as \overset{#2}{#1} for some characters

When I write math in xelatex, I like notation such as: $x \overset{ℝ}{+} y$ $x \overset{f}{↦} y $ $x \overset{(1)}{=} y$ However, as I type things like this so often, I would like to type it ...
2
votes
1answer
62 views

Improve command definition to avoid possible break

The following defines my MWE: \documentclass{article} \usepackage{amsmath} \usepackage{totcount} \newcounter{totalpoints} \regtotcounter{totalpoints} \newcommand{\shcpoint}[1]{% ...
9
votes
1answer
71 views

Using expanded macro as search pattern for \patchcmd

Is there any way to use the value of an expanded macro as the search pattern for etoolbox's \patchcmd (or xpatch's \xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of ...
4
votes
1answer
36 views

XParse: Command, which creates a command

SE, lately I'm playing around with expl3 and xparse a little and I encountered following problem: I want to create a command which creates a new command -- similar to this post. This is not as hard, ...
6
votes
2answers
141 views

Modifying fraction macro for in-line text and exponents

There's an amazing fraction macro here* for FontSpec with LuaLaTeX (*: that would be the second macro in that answer, called \unifrac, which I like better than the first "macro"/ using the frac ...
5
votes
1answer
26 views

macros - calling a command using an input variable

In the process of a project, I realized it would be helpful if I could do as follows. Say I have a list of different commands (simplified): \newcommand{\AA}{...} \newcommand{\AB}{...} ...
2
votes
2answers
43 views

How to automatically determine the remaining width of the text field in this form?

I have this form made with the aid of hyperref package using the form environment: \documentclass[pagesize=pdftex,DIV=16]{scrartcl} \usepackage{xcolor} \usepackage{hyperref} % ...
0
votes
2answers
21 views

How to draw a vertical line for separating specific section and content?

While editing my resume, I wanted to place vertical line to separate the section part with the content for the section. Photo attached for clarification. Like this, edited in a sketch app. ...
16
votes
1answer
360 views

Learning to use xparse

I'm learning to use xparse to build commands with optional arguments. But I'm having problems: I want to make a command called \topcat with output: \mathcal{O} if no argument is specified ...
2
votes
2answers
78 views

How to append data to a global string variable?

Here is a minimal non-working example: \documentclass{article} \begin{document} \let\@var\@empty \newcommand{\append}[1]{ \xdef\@var{\@var #1} } \append{1} \append{2} \append{3} \@var ...
7
votes
1answer
158 views

Have a command acting on the environment body

I need to turn this \begin{FOO} my little pony \end{FOO} into this \bar{my little pony} I have tried this: \newenvironment{FOO}{\bar}{} But this seems to only make \bar apply on the first ...
22
votes
3answers
10k views

How to add a custom symbol to LaTeX?

Suppose I need some crazy custom symbol for personal use. e.g. when I write \foobar, LaTeX should show . How do I achieve this? Update: I was writing Klingon writing system for fun. Thank you very ...
227
votes
6answers
45k views

Space after LaTeX commands

I have a definition: \newcommand{\arnold}{Arnold Schwarzenegger} When I refer to it by: \arnold is a it is rendered as: Arnold Schwarzeneggeris a In order to have a space in front of "is" I ...
26
votes
8answers
3k views

No space following macro without argument

With a macro such as: \def\naive{na\"{\i}ve} I find that the space which I would hope to follow it, is absent. So, with the \naive approach I get the naïveapproach in the output. How do I ...
1
vote
0answers
31 views

xparse verbatim argument removing multiple space

I am trying to define a command, using xparse that take as input some verbatim code and cite it using listing. However, the eventual multiple white spaces or tabulations at the beginning of a lines ...
1
vote
0answers
31 views

Escaped characters in labels

I am writing some API documentation, and since I don't like to repeat myself I would like to make some commands and call those for parts that get repeated a lot. However, I am having trouble with ...
1
vote
2answers
127 views

Generating a list with macros using tasks package

I cannot figure out how to generate a list with the tasks package using macros. If you swap the three identified lines in the MWE below, you should get the following error message: \begin{tasks} on ...
4
votes
1answer
40 views

Cut an email if the string size is upper than a value

I've a really long document that I generat with a python script. A big part of the doc uses longtable with an email adress: \begin{longtable}{p{0.3\linewidth}p{0.3\linewidth}p{0.3\linewidth}} value ...
2
votes
2answers
47 views

Automatically make three brackets the same size

I would like to do something like left[ and right], but with an additional | in between which automatically has the same size as the left/right. This comes from the way I denote conditional ...
2
votes
2answers
1k views

Use (or redefine a) \tag command in text mode

In some times I have to set a tag in front of a text math formula. It seems better to define a command \TAG, as $\TAG{Pythagoras' Equation}a^2+b^2=c^2$ to get <Pythagoras' Equation> a^2+b^2=c^2. ...
0
votes
0answers
13 views

All-or-nothing placing of macro-generated text [duplicate]

Given a macro % bold task titles \newcommand{\mypar}[1]{{\bf #1:}} %task decription template \newcommand{\task}[3]{ \mypar{#1} #2 \\ \emph{Solution:} #3\\ } I should like for the text ...
6
votes
3answers
2k views

Plain TeX vs. LaTeX Macros

I was wondering what's the (advantage) of doing something one way over the other in different systems. For instance, I read that users of plain TEX should use \def whenever they want to create a new ...
5
votes
4answers
250 views

Defining 'newcommand' without brackets

I know that in LaTeX newcommand is defined as: \newcommand{name}[num] {definition } But I want to define a new command whose argument is not defined between brackets, and it is defined with between ...
0
votes
0answers
40 views

Sorting macros by their first argument

Let's say I have a document consisting mainly of ''task''-macros that are defined as following: % bold titles \newcommand{\mypar}[1]{{\bf #1:}} %task decription template \newcommand{\task}[3]{ ...
1
vote
2answers
71 views

Macro in texstudio/texmaker to surround selected text with tags

When you use some of the predefined shortcuts in texstudio on selected text, it wraps the text with the appropriate tags(is that the proper term?). For instance, suppose i highlight Hello Worldand ...
6
votes
1answer
58 views

Is there a way to \uppercase greeks?

Here's a sample code, which works for latin math, but not for greek math. \documentclass{article} \providecommand{\bigset}[1]{\ensuremath{\uppercase{#1}}} \begin{document} \bigset d :-) ...
15
votes
3answers
401 views

Turn tikz drawing into a macro

I have created my own method of drawing a randomly generated closed loop. Here is my code: \documentclass[tikz]{standalone} \usepackage{pgf} \pgfmathsetseed{\number\pdfrandomseed} \begin{document} ...
2
votes
1answer
36 views

How can I implement xstring's \IfBeginWith equivalently in a non-user-level macro?

I have a string check macro \IfBeginsWith from xstring that is wrapped in a non-user level macro. I have learned here that the wrong approach would be to use user-level commands in a wrapper that no ...
6
votes
2answers
208 views

Why does \show\jobname result in \jobname and not the name of the file?

Should not the name \jobname expand to the name of the file without the extension? I looked at http://tex.stackexchange.com/a/36967/13552 It says that show results in the meaning of a macro. ...
3
votes
3answers
108 views

How to do simple arithmetic with arguments in ConTeXt?

This seems like a simple requirement but after reading the wiki and googling for answers, I can't figure how to express it for ConTeXt. What I want to do is define a macro with two arguments (or one ...
0
votes
0answers
68 views

Translations from other languages for English with Latex

The problem with doing translations in LaTeX is this: I use the Wordfast program to "record' everything that I tranlsate (Worfast is not a machine translation tool; it is a macro that runs inside ...
11
votes
1answer
202 views

Macro to capture until end-of-line as argument

Is it possible to capture the contents to the end-of-line as a macro argument? For example, consider the following naive visualization: \documentclass{article} \newenvironment{myitemize} ...
1
vote
2answers
82 views

Assigning variable a math code

I want all s2 words inside of my large text be automatically recognized as $\rm s^2$, so that when I have numbers of constants such as 9.8 m/s2, they will be automatically recognized as 9.8 m/{$\rm ...
3
votes
1answer
68 views

How to pass parametres to an external file included by `\input{<filename>}`

I have a class file to set up agreements. I want to define a command that choose boilerplate text to include using a parameter pass a parameter to the included file to run a test and choose correct ...
5
votes
1answer
139 views

macro for glossaries counter

I want custom my glossaries, and specially I want to have something like My glossary entry, its signification (see p. 1), if this entry mentioned only once or My glossary entry, its signification ...
1
vote
1answer
42 views

How to patch a starred environment

I would like to translate my approach to center all figure environments to figure* environments. How? \documentclass[peerreview]{ieeetran} \usepackage{xpatch} % ...
5
votes
3answers
108 views

Problem with subscripts in custom xparse commands from foreign files

When compiling this code: \documentclass{article} \usepackage{testPackage} \usepackage{xparse} \NewDocumentCommand{\foo}{mm}{#1_{#2}} \begin{document} $\foo A i$, $\fooT A i$ \end{document} ...
4
votes
1answer
154 views

list of all used commands in compiled *.tex-documents

Is it possible to get a list of all the commands used in the compiled documents? I mean, if I use in my various .tex-documents commands such as \emph, \section, \cite, \begin, \documentclass, ...
3
votes
1answer
42 views

Creating a command that concatenates an input string token by token

Using (first of all) xparse I want to create a command like this: \DeclareDocumentCommand{\c}{ s > { \SplitList { ; } } r""} { % do something } It basically should just do the following: ...
4
votes
3answers
144 views

Variable number of arguments in a command

Code \documentclass{article} \newcommand*\test[2]{#1\textsuperscript{#2}} \begin{document} The player ended as no.~\test{1}{} and her friend came ind \test{2}{nd}. \end{document} Output Question ...
2
votes
0answers
48 views

How can I costumize the ToC for 2 different types of chapters?

I already have ((re)new)defined a 2nd type of the \chapter macro for I have two different types of chapters. But they have one counter, which appears for every chapter in ToC. Here's a MWE: ...