{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
1answer
40 views

Using \newcommand to define nested commands

I am relatively new to LaTeX which is why even though I have tried to read up on \newcommand and various ways of how to use it, I still can't get the code to work. Here's the gist of it: I'm using \...
5
votes
2answers
74 views

Necessity of braces when creating newcommand using csname

Why does \expandafter\newcommand\csname hello\endcsname{Hello world} create a new macro while \expandafter\newcommand{\csname hello\endcsname}{Hello world} creates garbage? Form what I understand, \...
1
vote
1answer
23 views

Pluralize macro s, occasionally

I define a key term in my preamble, because we are still sorting out how to spell it ('soft goal' vs 'softgoal'): \newcommand{\sg}{softgoal} However, we also use this in plural form, which is simply ...
2
votes
1answer
63 views

WinEdt LaTeXify macro install fails to install toolbar buttons

I just installed the LaTeXify Macro in WinEdt 10.1 20160526 build on 2 computers. First up Win 8.1 box - everything okay! Second up Win 7 box not so much. The main menu TeX -> PDFLaTeXify, Biber, etc. ...
0
votes
2answers
60 views

Help defining a newcommand for short cut to equation

Is there anyway to define a newcommand for an environment shortcut ? This is what I have so far, but is not working as I would like to. \newcommand{\beq}{\begin{equation} \label{eq:} and \...
4
votes
1answer
40 views

Macro expanding in an undesired fashion

I’m working on my thesis which is (of course) written in (Xe)LaTeX and which extensively uses the natbib package and bibtex for citations, including features such as \citeauthor{reference}. Since my ...
17
votes
3answers
579 views

Extract first word in a string

The title pretty much says it all, I need a command to get the first word in a string. Based on this answer to another question of mine, I tried this: \documentclass{article} \makeatletter \...
0
votes
0answers
41 views

How to create a specific code listing macro

I am trying to reproduce a macro in latex that would allow to insert code in this format: So there is a header with listing number that is starting from the left side of the document. It is between ...
1
vote
1answer
85 views

How to put a text at the end of the last sentence of a document with xelatex?

I have a lot of documents witch all have to share the same last text. But this text have to follow the last sentence immediately — without line break —. I try to modify the document environment but ...
4
votes
1answer
254 views

Negative phantom inside equations

The following code produces a negative phantom (from the comment in this answer): \newcommand{\negphantom}[1]{\settowidth{\dimen0}{#1}\hspace*{-\dimen0}} However, when used inside an equation like ...
4
votes
1answer
130 views

Single letter macros

In this post I learned that single letter macros purportedly have a significant impact on the typesetting process. For the past n many years I have been redefining letters like '\d', '\x', '\z', and '\...
1
vote
1answer
47 views

Latex won class and macros

I'm writing my own simple template, what I have so far is a new, redefined make title command: \NeedsTeXFormat{LaTeX2e} \ProvidesClass{myclass}[2016/06/22 My custom class] \LoadClass{article} \...
5
votes
2answers
162 views

What's the purpose of nesting a \def within a \newcommand?

I recently found the following piece of code: \newcommand{\ISBN}[1]{\def\ISBN{#1}} Isn't it redundant? What's its purpose? UPDATE I now understand its purpose. I have never seen it before. Is it ...
4
votes
2answers
137 views

Nested Logic Gates

I am trying to get a nand gate to work like the one mentioned in this article, and it takes issue with the ifnum being fed a single integer rather than a pair of integers with an equals. When I fix ...
2
votes
1answer
84 views

Renew command not working

I have the following command written in my preamble \renewcommand{\d}{\;\ensuremath\mathrm{d}} but get the error LaTeX Warning: Command \d invalid in math mode on input line 11. This only ...
0
votes
0answers
44 views

Creating macro for double-Sig rune (SS)?

I'm (almost) a complete novice when it comes to TeX, and this question is more for my curiosity than anything else... I've read quite a few books about WWII and the Nazi-German occupation of Europe, ...
6
votes
1answer
127 views

How to remove the space after an empty note in \autocite?

I am currently writing my thesis, and I would like to put a placeholder for "cf." in my autocite like so: \autocite[\cf][]{Author.2016} Reason: in case my mentor wants me to use a citation style ...
5
votes
3answers
116 views

A macro that processes and hides text?

I'm writing a solutions manual for a text. Some of the solutions are only supposed to be visible to the instructor, so I've written a macro \newcommand{\instructor}[1]{} which hides its argument. ...
3
votes
1answer
43 views

indexing woes with macro arguments

I have asked strip last character from parameter if it is 's' and I was given an answer. However, it turns out my case is little bit more complicated. Some of the monsters have hard to type ...
4
votes
3answers
119 views

Separating sub-/superscripts out

I'm looking for a way of separating super-/subscripts (if they exist) from a LaTeX command argument. As an example, imagine you want to define a command that builds multisets from sets by placing an ...
6
votes
5answers
570 views

strip last character from parameter if it is 's'

I have a semantic annotation \monster to annotate mentions of monsters so that they are indexed: \newcommand{\indexMonster}[1]{\index{#1}} \newcommand{\monster}[1]{#1\indexMonster{#1}} Now, most of ...
1
vote
1answer
54 views

Remarks using Changes Package

Using the changes package, how can I create a 'remark', which is displayed in the same markup colour formatting, and included in the list of changes when in draft or normal mode, but is removed ...
3
votes
1answer
226 views

Can I reobtain a command I've overwritten with renewcommand?

I've overwritten the \bullet command using \renewcommand (which in hindsight, was a bad idea...). After using the new \bullet command for quite a while, I've realized that it behaves badly in certain ...
2
votes
1answer
43 views

file ended while scanning use of \path

MWE: \documentclass{article} \usepackage[obeyspaces]{url} \usepackage{xcolor,letltxmacro,booktabs,longtable,tabu} \LetLtxMacro{\oldpath}{\path} \renewcommand{\path}[1]{\color{gray}{\oldpath{#1}}} \...
0
votes
0answers
11 views

Using arguments in \newenviroment together with \caption [duplicate]

I created \newenviroment for "professional tables": \newenvironment{tabpo}[1]{% \begin{table}[!ht] \centering \begin{tabular}{lllllll} \toprule } {% \bottomrule \end{tabular} \caption{Arg:...
4
votes
2answers
125 views

How to define a blank-independent macro

How would I define a macro \test , e.g. using \def\test#1{...}, that can be used in the two following ways? The usage without a blank \test{A}This is some text as well as the usage with a blank \...
1
vote
3answers
58 views

How to convert \textwidth to mm and use the number as a command?

I am trying to convert \textwidth to other units I want and do calculations with the number (without the unit). How does one do this?
1
vote
1answer
67 views

Using counter in csdef

I'm trying to implement a map: counter => string + another_counter: 1 => eq1 2 => eq2 3 => ineq1 ... I use \csdef like this: \csdef{probName\thecntProblem}{\csuse{filePrefix}\arabic{...
8
votes
4answers
192 views

Dynamically filling a grid with TikZ from a data array

I have been trying to fill an grid with "binary" type data, so you iterate through an array that is 2D and these 1s and 0s decide if a location is filled or not. This is my first foray into ...
2
votes
0answers
45 views

\strip@pt\textwidth gives “undefined control sequence”

I'm sure that this is something silly, but I've been beating my head against the statement \strip@pt\textwidth giving "undefined control sequence". I'm trying to modify some drawings in tikz widths ...
9
votes
1answer
239 views

Using {\AA} when \r is redefined

I'd like to use {\AA} to input a capital A with a ring above. However, the document I am writing has to import some definitions which I have no control over. One of the definitions changes \r: \...
3
votes
1answer
56 views

How to correctly create a macro for a table?

I am trying to apply the following answer: http://tex.stackexchange.com/a/72916/25124 What is wrong with this code? I am trying to define a macro to be able to specify a table of 3 columns but whose ...
1
vote
1answer
29 views

Why does embedded \g@addto@macro sometimes fail?

I decided to test my understanding of expansion and embed \g@addto@macro within another three macros. \g@addto@macro \appendmacro \layertwo \activatelayerone From my understanding, the ...
2
votes
1answer
73 views

How to write macros?

I'm very new to TeX and am only learning it to write in MathJax on the math stackexchange. I've just discovered that I can write macros to make it easier to do repeated things, but I'm having some ...
4
votes
1answer
46 views

Package Neuralnetwork label neurons independently

I have a problem which I can not solve. I'm quite new to the world of LaTeX and I don't know much about macros. Heres my problem: I draw a Neural Network using the Neuralnetwork package. I have an ...
2
votes
4answers
192 views

How can I pass a macro to a macro and check for its existence?

I hope this question makes sense. If I wanted to modify the following code to allow the user to pass a macro as the first parameter, how would I do it? How it is: (using pgf) \def\appendtolist#1{% &...
2
votes
1answer
65 views

Can't compile with BibTeX

I'm creating a document in LaTeX with the bibliography in a separated BibTeX file. When I compile the document without any reference to the bibliography it runs correctly, but when I add references ...
1
vote
0answers
60 views

Where is \noident defined? [closed]

As always, I have the following: \documentclass{article} \usepackage[utf8x]{inputenc} %∑ \usepackage{hyperref} %clickable x-ref-s \usepackage{url} %\usepackage{fixltx2e} \usepackage[margin=...
4
votes
1answer
39 views

Ignore undefined key in argument (it's defined in the macro before it's used)

How can I make this macro initially ignore the undefined key fn-special-text in the second argument? It is defined within the macro (because the name is generated from the text of the first argument; ...
4
votes
1answer
59 views

Quarter turns according to coordinate axes in TikZ

I'm trying to implement quarter turn style arguments in TikZ, in such a way that \begin{tikzpicture} \path (2cm,1cm) coordinate (A); \draw[blue,->] (A) [northwestqturn=3cm]; \draw[green,->] (...
5
votes
3answers
384 views

Can I define a macro that accepts everything until the next space?

I'd like to make a shortcut macro to prefix function names in formulae to decorate them in some way depending on the function type. Using "normal" macros would lead to an abundance of braces and I'm ...
4
votes
1answer
36 views

Abbreviations for align

I know from the Technical notes on the amsmath package that it is not possible to introduce direct abbreviations like \newcommand{\bal}{\begin{align}} % doesn't work \newcommand{\eal}{\end{align}} %...
6
votes
1answer
40 views

LaTeX3 Regex using control sequence

I'd like replace some words/characters using l3regex on a arbitrary variable. Instead of doing this \tl_set:Nn \l_myname_tl {Hello} \regex_replace_all:nnN {(\w+)} {\1 World!} \l_myname_tl which ...
7
votes
3answers
185 views

Draw circle in TikZ by specifying endpoint and distances instead of angles and radius

In the classical arc command in TikZ, we specify an endpoint of the arc, followed by the initial and final angles, and finally the radius. I would like to create a macro (if it doesn't already exist) ...
11
votes
1answer
287 views

Solution to 'Multiple PDF generation with one tex file' does not work anymore with TeXLive 2016

The solution in Multiple PDF generation with one tex file worked with TeXLive 2015 and is now broken in TeXLive 2016, at least on OS X El Capitan. Minimal Example: \documentclass{article} \ifx\...
1
vote
2answers
90 views

Automatically generate new commands and keyval definitions

I would like to automatically define new commands and keyval definitions anytime that a command beginning with the prefix \fn is used within a string. Part I below is the stub that needs to be ...
0
votes
0answers
13 views

Variable name space problem [duplicate]

I have a problem with defining a variable in latex. Here is the deal: I create a variable containing a string like this: \newcommand{\company}{{Company Name}} It works, but the problem is when I ...
5
votes
4answers
196 views

Macros that define other macros, which also define other macros

I would like to define a TeX 'macro-building' command (let us call it \buildmacro) that takes as argument a string of 'normal' characters (e.g., Title) and which satisfies the followings: the ...
7
votes
1answer
78 views

Macro overloading, catcode redefining… or how can I parse XML with TeX?

Given this code that barely parse XML and print it as SXML (s-exp XML, aka lisp-style XML, aka XML-with-parenthesis): \catcode`@=11 \let\@xp\expandafter \def\@makeletter#1#2\@nil{\catcode`#1 \ifx\...
6
votes
2answers
69 views

Latex3 equivalent csname endcsname

I would like to know how to create dynamic named macros (in a loop) in Latex3. Everythings ok in LaTeX2e. I look to something equivalent to that code with expl3 \stepcounter{N} \expandafter\def\...