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

4
votes
2answers
14 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, \...
130
votes
3answers
85k views

How do I create an invisible character?

I cannot remember how to create an invisible character in LaTeX, i.e. I want to put a space the that has the width of a particular character, say `M'. I know there is a command for this, and this is ...
11
votes
2answers
459 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 \...
2
votes
1answer
30 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. ...
1
vote
1answer
20 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 ...
1
vote
2answers
43 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
39 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 ...
1
vote
1answer
80 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 ...
0
votes
0answers
33 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 ...
2
votes
4answers
188 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
241 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
123 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
46 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
156 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
133 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
77 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
34 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, ...
5
votes
3answers
115 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. ...
6
votes
1answer
125 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 ...
1
vote
1answer
50 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 ...
6
votes
5answers
555 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 ...
4
votes
3answers
116 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 ...
3
votes
1answer
39 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 ...
0
votes
1answer
64 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{...
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}}} \...
3
votes
1answer
225 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 ...
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:...
9
votes
2answers
298 views

Associate counters — stepping (many) counters simultaneously

This is (perhaps) not a real question and there maybe already an answer to my proposition/request. The situation There are packages that provide the number of the last page (i.e. lastpage or the '...
4
votes
2answers
123 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
55 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?
8
votes
4answers
187 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
42 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
230 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: \...
11
votes
2answers
369 views

Use lualatex to create macros

I used the following in the past and it worked: \documentclass{minimal} \usepackage{luacode,luatextra} \begin{document} \begin{luacode*} MyVal=123 tex.print("\\def\\MyVal{"..MyVal.."}") \end{luacode*...
3
votes
1answer
55 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
27 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 ...
4
votes
1answer
43 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
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 ...
2
votes
1answer
60 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 ...
4
votes
1answer
37 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; ...
1
vote
0answers
57 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=...
11
votes
1answer
279 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
87 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 ...
7
votes
3answers
180 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) ...
4
votes
1answer
58 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
380 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
35 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 ...
19
votes
4answers
2k 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 ...
2
votes
1answer
99 views

Math mode macro in TeXstudio

I want to set up a macro in TeXstudio for math mode which displays $*$ and places the cursor at position *. So far I have tried using $%|$ but upon triggering, this macro does not allow text insertion ...