{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.
4
votes
1answer
68 views
Command to insert filename in caption of a listing
I would like to have a command to insert listings that contain the filename in the caption. This works well as long as there is no "_" etc. in the filename.
I also tried the suggestion from a ...
3
votes
1answer
54 views
List Version of \str_if_eq
I am using \str_if_eq:xxTF{\A}{\Target}{<true>}{<false} to execute the <true> or <false> code if \A=\Target.
What is the list version equivalent of this?
So I am looking for ...
3
votes
1answer
102 views
Why do I get the error “! Illegal parameter number in definition of \appendix.”while redefining the \appendix command?
I'm trying to redefine the \appendix command so that my appendix headings go to the top of the pages. To do this, I tried the following code, but I get the error ! Illegal parameter number in ...
6
votes
2answers
90 views
Complex parsing of arguments in new environments
I am trying to build an invoice generation system in LaTeX which will be easy and maintainable. Right now we are using longtable and a preprocessing layer. I would like to change this to a .sty and ...
2
votes
1answer
64 views
How to create an optional argument like the 'correctchoice` command in exam document class?
I want to create an alternative to CorrectChoice. That when [answers] command is used it will highlight the correct answer and be printed with the question together.
I have seen this command by this ...
6
votes
1answer
138 views
Applying condition around \intertext and \shortintertext leaves excess vertical space
When I try to make either \intertext or \shortintertext conditional I get excess vertical spacing prior to the conditional text as per the MWE below. Note the excess vertical spacing prior to "Albert ...
2
votes
1answer
55 views
Automate replacement of `\not` when in `\bm` mode
Hendrik Vogt has provided a \longnot macro to alleviate the issues related to
Interaction of \boldmath and \not. This seems to work fine, but I run into a snag when I try to automatically use ...
9
votes
1answer
130 views
Is there a way of defining a command which is automatically converted to a no-op after its first execution?
Is there a way of defining a command that can be executed only once and is then redefined to be a no-op?
Related:
Is there a way of defining a command \nullifyifmoved{arg} that will normally act ...
3
votes
1answer
76 views
How can I use renewcommand for toprule of the booktabs package?
I have a LaTeX document and want to change the thickness of \toprule and \bottomrule to 1.5pt.
Is there a way to do this with the \renewcommand or do I have to change every \toprule to ...
7
votes
3answers
110 views
I want to create a command that will conditionally gobble up trailing whitespace: I want an “\unxspace” command
I have a command that occasionally produces whitespace that I don't want.
\def\testa{a}
\def\testb{a}
\newcommand{\mycommand}[1]{\ifx\testa\testb{#1}\fi}
When \testa and \testb are different, I ...
4
votes
1answer
98 views
Using Hashtag in macro
I had a problem putting the column headers in bold (in a table of course) using pgfplotstable. You can see the problem here
I found a way to work arround that. It isn't generic as I wanted it to be, ...
2
votes
2answers
120 views
How to define new command for commands like \frac{} or \int{}^{}?
We know that we could define a new command for boldfaced or calligraphic C, for example I can define \newcommand{\Cx}{\mathbb{C}}, which will produce the boldfaced C, i.e. $\mathbb{C}$ for me. But how ...
5
votes
3answers
97 views
Metacommand for commands that dynamically select a parameter?
Original question
I would like to create a metacommand for creating new projection commands. Specifically, \newproj{\cmd}{<n>}{<m>} should create \cmd as a new command of <n> ...
5
votes
2answers
126 views
How to use variables inside a command when generating a table?
I'm not sure about the question, since I do not really understand why it fails.
I tend to use commands to generate my tables, and when I use the #1 style of accessing the arguments it works. But now ...
3
votes
1answer
82 views
Is it possible to redefine \alpha this way?
I was thinking about doing something crazy, namely, I want to define a "newcommand" by
\renewcommand{\alpha}{\ensuremath{\alpha}}
so that later in text mode I can just do \alpha instead of $\alpha$ ...
16
votes
6answers
413 views
A new environment to decide dynamically which commands to run?
I am having some user defined commands defined and used in my latex document. I need a way to check whether any of the commands is used. I want to make decisions based on the argument used in the ...
0
votes
0answers
40 views
Help on numerical argument with newcommand [closed]
I want to create a necommand with a numerical argument as below with a default value. If I only use the default value, it works fine, but if I use a number as argument, it will not work as i want. ...
0
votes
0answers
35 views
Create two small box after text? [duplicate]
how should i declare a command for two small boxes after text in every line? based from this link Create a two column static small box. I need to remove the automatic printing of its numbers. What ...
0
votes
2answers
86 views
Creating a command similar to \vrule
Upon trying to create a new border similar to the \vrule command, I have the following:
\documentclass{article}
\usepackage{xcolor,framed,lipsum}
\def\bulletfill{\vbox to ...
4
votes
3answers
163 views
How are space tokens and empty lines processed by long commands (as their potential arguments)?
How are spaces and empty lines processed by long commands (i.e., those that do not accept paragraph breaks inside)? Are there different space tokens aside from " " and an empty line? It appears that ...
6
votes
2answers
112 views
Using a character as a macro within another macro in (La)TeX
Goal: What I would like to do is to allow _ and ^ to be used to generate sub and superscripts in text mode only within a specific macro. I know that I can make _ and ^ active throughout the document, ...
19
votes
3answers
241 views
If I redefine a command that has a starred variant, will that always disable the starred variant?
If I redefine a command that has a starred variant, will this always effectively disable the starred variant, as a side effect of redefining the unstarred variant?
A related question: Do starred ...
2
votes
0answers
105 views
How to prevent continuation to the next page? [closed]
i learned of the samepage environment based from this link Unbreakable block so i tried it on my case but i think this isn't what I am looking for. My problem is: with the exam class, i have created a ...
5
votes
1answer
213 views
How do I typeset the name of this site in (La)TeX?
How do I typeset the name of this site (TeX.SE) in (La)TeX?
And, what is the name of this site? I thought TeX - LaTeX was technically correct, but another user suggested something similar to \TeX{} ...
2
votes
1answer
72 views
Automatically add theorems to index and label them
In another question (Remove math from command parameter to get only the letters) this command was elaborated to have an optional argument for sorting purposes within the index
\documentclass{article}
...
5
votes
3answers
107 views
Remove math from command parameter to get only the letters
I use a little command, which prints new defined terms in bold, adds a label and adds them to the index.
\newcommand*{\defined}[1]{{\bf #1}\label{#1}\index{#1}}
Now if I do \defined{$G$-invariant} ...
6
votes
3answers
143 views
Aligning image and text in new command in TikZ
As a Teaching Assistant for a class, I am trying to draw a seating chart for the professor. The seating chart will have a photo of each student, the student's name, and where the student is sitting in ...
4
votes
1answer
53 views
automatic nomenclature breaks with subfigure
I am using the method recommended in
List of symbols/abbreviations and macros
to automatically generate an entry to the nomenclature (nomencl package) when I first use a command, i.e.
...
6
votes
1answer
55 views
\newcommand with adjustable size
I'm soon going to take Live-notes of a course where Tensors are commonly used.
Tensors consist of a Letter, say T, with numerous sub-and superscripts.
Generally, a tensor could look like
...
10
votes
1answer
182 views
Interaction of \boldmath and \not
It seems that using \boldmath (or \bm) along with the \not does not quite work so well. Here is an example using \not\subseteq and \not\le
where the line representing negation does not stretch ...
3
votes
1answer
75 views
Create command not using adjustbox package for inserting image
I am creating a test question using exam.cls and I think it would be different if i will include image in the question. But i dont really know how should I insert it.
i found a solution code that ...
4
votes
1answer
90 views
Create command to inline an image in a question?
How to create a command to can insert the image in a line of text question? Since I have a lot of question types made True/False, Short Answer types, Multiple choice, etc. I want the command to be ...
4
votes
2answers
106 views
Why can't I insert a blank line in this code?
In the code below, everything is OK until I insert a blank line instead of one of the \\'s. Upon inserting a blank line, I'll get some errors. How can I get rid of these errors?
...
17
votes
3answers
377 views
Always use \NewDocumentCommand instead of \newcommand?
Are compelling reasons to stick with \newcommand or should one always use \NewDocumentCommand instead, even when not using any of the additional features offered by xparse?
In addition and more ...
4
votes
1answer
77 views
cool package derivative and eulervm \mathbold fails with 'Missing control sequence inserted.'
Compiling
\documentclass{article}
\usepackage{cool}
\usepackage{eulervm}
\begin{document}
$\D{a}{T}$
$\pderiv{a}{T}$
$\mathbold{T}$
$\D{a}{\mathbold{T}}$
$\pderiv{a}{\mathbold{T}}$
...
3
votes
1answer
145 views
How do I create the following macros?
I would like to define the following macros.
\newcommand{\NC}{\ensuremath{\mathbf{NC}}}
\newcommand{\NC}[1]{\ensuremath{\mathbf{NC^{#1}}}}
But LaTeX complains that \NC is already defined. So, I ...
3
votes
2answers
114 views
Toggle visibility of solutions in LaTeX output for exams
So I have my own layout for my exams based on scrartcl and to prevent anomalies during some changes I want to have only one file per exam which holds both questions/excercises and solutions. Yet I ...
5
votes
2answers
62 views
passing current content of commands to a macro
I am sorry for this is probably a current question with a well known answer, but I was not able to google it out.
I am trying to build a macro adding content step by step; at every step I need to ...
2
votes
1answer
48 views
Biblatex custom cite macro
I don't really understand how to use macros, but this would be a good way to learn.
Currently, I simply use \cite, which prints Author, Year. When I have this in a sentence, I want the year to be in ...
8
votes
1answer
121 views
Which commands exist to define new commands?
Which commands are there that one can use to define new commands in (La)TeX?
There are: \let, \def, \[re]newcommand[*], \DeclareRobustCommand[*], and ...?
(And I've seen things like ...
8
votes
1answer
121 views
how to redefine \begin{align*} … \end{align*} to \begin{eqnarray*} … \end{eqnarray*}
Scientific word insists in generating displayed math using
\begin{align*} ... \end{align*}
and htlatex has a bug in that it does not generate bit mapped images in this case.
The fix that I found ...
16
votes
4answers
403 views
Do starred commands eat up space after them?
Do starred commands eat up spaces after them, like unstarred ones do? That is, is \somecommand* nextword equivalent to \somecommand*nextword?
And: Does it depend on the particular way a starred ...
7
votes
1answer
69 views
Is there any reason against changing the starredness of a command upon redefinition?
If an original definition of a command used \newcommand, is there an obligation for me to redefine it with \renewcommand instead of \renewcommand*?
If an original definition of a command used ...
11
votes
2answers
106 views
Is there any reason to define a zero-argument macro using a starred defining command?
Is there any reason to define a 0-argument (read: zero-argument) macro with a starred command (\newcommand* instead of \newcommand or \DeclareRobustCommand* instead of \DeclareRobustCommand)? After ...
0
votes
0answers
64 views
True `macros' in (La)TeX [duplicate]
When using \newcommand and the like, LaTeX seems to create a new box for the content (I'm probably observing things wrong). For example, I have \newcommand{\p}[1]{\ensuremath{\left(#1\right)}} in my ...
0
votes
1answer
68 views
Expansion of single line vs multiple line gather
As described in Multiple split equations I want to create an equation environment that inserts aligned and lets me split equations with \n. The solution I found there is a bit hackish I guess, but ...
5
votes
3answers
144 views
\includegraphics optional argument not resolved if macro
\documentclass[a4paper,10pt,twoside]{book}
\usepackage[demo]{graphicx}
\begin{document}
\newcommand{\scalefactor}{scale = 0.25}
\begin{figure}[!ht]
\centering
%Next line does not work
...
4
votes
2answers
95 views
Line break (continuation) for commands (options, arguments)
How to do proper line breaking (continuation) for commands, i.e. their options and/or their arguments? For example, in order to transform this:
\usepackage[top=1.0cm, bottom=1.0cm, left=1.0cm, ...
2
votes
1answer
62 views
How to put R code into a parameter of a newcommand?
I would like to put R code into a parameter of a newcommand in LaTeX. To do it, I make the following:
%Define the newcommand:
\newcommand\solution[1]{\sf #1}
%Then, after the \begin{document}, I ...
7
votes
1answer
132 views
Generating code examples
I would like to make a table showing some custom commands that I have defined. It would be nice if I could do something like the following.
\documentclass{article}
...
