{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.
6
votes
2answers
53 views
Modify Tag Command
Fairly sure this is something really obvious.
Trying to redefine the \tag{...} command via:
\let\tagOld\tag
\renewcommand{\tag}[1]{\tagOld{#1$^*$}}
In other words, it appends an asterisk to the ...
1
vote
0answers
34 views
Expand command read from file
I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
8
votes
3answers
54 views
How can I collect the contents of a LaTeX environment in a macro without the grouping?
It's a bit of a long story as to why I need to do this, but please bear with me. I have a fairly complicated custom class which expects documents to begin with a command:
\coverandabstract{Abstract ...
5
votes
0answers
66 views
What is the difference between \def and \newcommand (Part II)? [duplicate]
A previous question What is the difference between \def and \newcommand? has discussed the difference between \def and \newcommand at some length. However, I cannot find in that discussion an ...
0
votes
0answers
30 views
How to test if an command is empty {}? [duplicate]
I used \newcommand* foo {} to define a command so the user could set it later via \renewcommand* foo {content}. How do I create a conditional statement (if then else) that tests if foo is empty ("{}") ...
6
votes
1answer
53 views
Difference between 11 and 12 catcodes
I can only define commands, consisting of catcode-11 symbols or single catcode-12.
What is the point of this limitation?
It would be convient for me to define commands, that include following, not ...
6
votes
1answer
81 views
Commutative Diagrams
Can anyone help me in giving commands for commutative diagrams in LaTeX ? It doesn't seem to appear properly in the LaTeX guides that I have. A command for a simple triangular diagram with arrows ...
3
votes
1answer
36 views
Change \newcommand behaviour based on the environment
I'd like to define a command \Lm, such that if used in a maths environment it is replaced with \mathcal{L}, but when used outside of the maths environment it would be replaced with $\mathcal{L}$. This ...
8
votes
2answers
58 views
Preserving (and Controlling) Expandedness
In most cases, by the time output gets to your screen, arguments are fully expanded and my question is moot. But sometimes (verbatim being a common example), one wishes to operate on arguments with ...
2
votes
1answer
45 views
How to store and append text for later use (inside enumerate environment)
I'm trying to make a traceability matrix (or table). For my purpose it's easiest if I can create rows anywhere in the document, store them in some kind of container and later use this container to ...
1
vote
2answers
63 views
How to apply a macro to each row of a table
This is similar to the question about cells, but with whole rows, and hopefully will help me to implement an answer to this question.
Given a macro \RowMacro, how can I define the mytable environment ...
1
vote
2answers
52 views
newcommand for $\frac{\mathrm{d}^4q}{\left(2\pi\right)^4}$
Can you give any hints on how to define a new command that writes
$\frac{\mathrm{d}^4q}{\left(2\pi\right)^4}$
with the options that one can write $p$ instead of $q$ (say) and also if one could ...
5
votes
1answer
41 views
Formatting a comma separated list of values
I'm creating a set of mathematics worksheets, and I'd like to have an upside down "answer key" below a set of enumerated questions. Here is what I have at the moment:
\usepackage{graphicx}
Answers:
...
5
votes
1answer
43 views
Use \LetLtxMacro with a \Macro* (starred variant)
If I use:
\LetLtxMacro{\MacroToUse}{\FormatText}
then using \MacroToUse invokes \FormatText exactly as desired. But, how do use this construct to invoke \FormatText*?
The MWE below yields:
but ...
7
votes
1answer
50 views
Purpose of \do@noligs in LaTeX verbatim environment
I'm trying to figure out how the verbatim environment works. In the basic LaTeX file latex.ltx I find the following definition (line 4037):
...
2
votes
2answers
39 views
Multi-line text retrieved from file via \input, within a newcommand declaration, passing newly declared command as argument of standard letter class
I have put together a minimum working example consisting of a number of files
mwe.tex % instance of personal letter
address.tex % full address of individual being addressed in mwe.tex
...
1
vote
0answers
38 views
Define tikz node based on pagenodes
I want to define a tikz node called current grid area based on the nodes defined by the tikzpagenodes package. This node is a rectangle that contains the 4 nodes defined in the package; current page ...
15
votes
3answers
147 views
Defining Extensible macros
Question:
For a macro that has only one parameter, are there any issues with defining it as follows:
\NewDocumentCommand{\MyMacro}{%
s% #1 = starred variant (*** unused as of yet ...
4
votes
1answer
36 views
Use of \cals doesn't match its definition \calscommand
The following minimal working example employs a cals table in the document environment and works fine:
\documentclass{article}
%document encoding
\usepackage[utf8]{inputenc}
%geometry
...
5
votes
2answers
50 views
Define a command for vectors, boldface letters, but not numbers
The purpose for this would be to leave scripts out of the equation. For example,
\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}
...
\vec{x_0}
would print the 0 as boldface, too. I know I can ...
17
votes
2answers
231 views
Difficulty with macro expansion (updated)
I'm not getting the output I want from my LaTeX code, and I think the problem is that I'm not expanding things at the right times.
Code
\documentclass{article}
\usepackage{tikz}
...
5
votes
3answers
49 views
Create an array of variables with string keys
I'd like to have a macro where I can insert a key as argument and get a value which I have defined before.
This should be similar to Create an array of variables but with strings/text instead of ...
4
votes
4answers
86 views
Defining a new environment extending a verbatim environment
Why is it not possible to define a new environment that extends a verbatim environment?
Consider, e.g.:
\documentclass{article}
\newenvironment{myverbatim}{\tiny\begin{verbatim}}{\end{verbatim}}
...
4
votes
3answers
37 views
Using variables in a command results in ! Argument of \reserved@a has an extra }
I want to define a command, which separates a string an later adds a different \href to the first part, than to the second (e.g. \qname{foaf:Person}). But the code as I have it doesn't work, I get ! ...
6
votes
1answer
42 views
amstex: operator definition error
I can't understand why the following code give me an error
\input amstex.tex
$\mathop{\rm arctg}(x)$
\bye
Thus, the input does not work with my macros that include the use of \rm, \mathop, etc., ...
4
votes
1answer
62 views
Numbers in \newcommand not working
I am trying to use the chosen solution shown here, for being able to use numbers in the alias I need for \newcommand. (That one is not able to use numbers in the alias directly strikes me as ... well, ...
10
votes
1answer
53 views
extrarowheight vs arraystretch
What's the difference between these two in a table environment?
I've seen they cause somewhat the same result, but I have no idea what is the difference, except that arraystretch is used in a scale ...
7
votes
1answer
59 views
String Comparison with a \protected\def
I am using a \protected\def as that solved an earlier issue of mine. I need to compare this value of the token to see if it is initialized to the same value as the \protected\def in different ways.
...
2
votes
2answers
64 views
Undefined control sequence \pgfmath@
Why does the following code give me this error message?
Error
ERROR: Undefined control sequence.
--- TeX said ---
\pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@
l.28 \draw ...
3
votes
1answer
59 views
A list of pairs in pgfkeys
Having learnt a lot about the pgfkeys package as a result of my last question, I'm now trying to do some more adventurous things.
Let's say I have a command called \blob, whose value is the ...
7
votes
2answers
158 views
Stupid error caused by doing stupid things
When I was writing my thesis I wrote the following two commands which I found useful (and still do). They are both ways of defining other commands.
\usepackage{ifthen}
\makeatletter
\def\optional ...
18
votes
5answers
234 views
How retrieve items in a list of words by number?
I'm working on a character sheet for the Fate RPG, which rates its skills with a numerical scale that corresponds to an adjective scale. I've been trying to write a macro that will take \skillAdj{4} ...
9
votes
2answers
93 views
What does \secdef do?
The definition of the chapter command in KOMA-class scrbook is:
\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{\chapterpagestyle}%
\global\@topnum\z@
...
8
votes
1answer
112 views
How to disable \renewcommand
I've got a custom class derived from report. I defined some standard commands inside of it to reflect its specific, so they look like:
\newcommand\contentsname{Custom Content}
...
5
votes
1answer
109 views
XML or other markup to LaTeX?
In my university project I am doing software testing - planning, implementation, evaulation. All test documents have the format:
General information
Test categories
Test cases
Test implementation ...
3
votes
1answer
50 views
Setting initial value of a storage macro
When I create a "storage macro" I often initialize it to be empty with
\newcommand{\@mymacro}{}
\newcommand{\mymacro}[1]{\renewcommand{\@mymacro}{#1}}
Instead of initializing it to empty I could do ...
2
votes
1answer
26 views
using a restatable before it is stated
This question is related to the question at Recalling a theorem, which uses the thmtools and thm-restate packages and the restatable environment to define a theorem that can be re-stated later on.
Is ...
3
votes
2answers
55 views
Section command with default spaces between title and rule
Ho can I make a section command that have the same spaces between the \titlerule and the title of the original \section command? The overall look must be equal to the original \section command. So, Is ...
9
votes
4answers
290 views
Macros: MS Word vs. TeX & friends
This is a follow-up question to How to convert TeX-illiterate coworkers to LaTeX?.
To better demonstrate the power of TeX & friends and dismiss the competition (e.g. MS Word, Open Office), I need ...
3
votes
1answer
46 views
How can by macro as parameter of other macro?
\StrPosition{AQ2 K863 1065 J1065}{ } give 4
\StrMid{AQ2 K863 1065 J1065}{1}{4} give AQ2
\StrMid{AQ2 K863 1065 J1065}{1}{\StrPosition{AQ2 K863 1065 J1065}{ } } i want AQ2
but give error message.
6
votes
1answer
38 views
Count words separated with comma in macro
I need to count number of words in a macro defined as follow:
\def\columnNames{MATRIX, METHODA, METHODB}
I manually set number of words as follow:
\pgfmathsetmacro\numberOfColumns{3}
I need an ...
11
votes
2answers
78 views
Patching arguments inside a macro
Consider the following example of a patch using etoolbox and a dummy macro \abc:
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\abc}[2]{#1\ #2}% Magic ...
2
votes
1answer
46 views
Command to write MIMO configurations
I want to write something like MIMO (multiple-input and multiple-output) configuration 2 x 2, 2 x 4, etc. and be consistent all over the document. For now I have defined a command to do that as I put ...
3
votes
1answer
30 views
parametrized variable with if else statements
I need to create parametrized variable \mycolor like in this example.
The variable \mycolor defined colour based on an argument. I need to compare #1 with values 1, 2 and so forth, but how to use if ...
7
votes
2answers
58 views
Setting an “attribute” for Theorem to be accessed later
I am writing a math paper with a large number of theorems. I'm looking to have a table summarizing my results, and I'd love it if the table could be generated automatically from my paper. I' looking ...
3
votes
1answer
62 views
To-do-notes in separate TeX File, but without \listoftodo in main doc
I am using the todonotes package and have three requirements, the first two which the MWE already does:
Obtain a list of todo notes in a separate auxiliary file. This can easily be obtained via the ...
3
votes
2answers
63 views
Changing line spacing within a new command
I have a command written as follows:
\documentclass[12pt]{book}
\usepackage{setspace}
\newcommand{\statshyp}[2]{\noindent \hangindent=1cm \hangafter=0
\begin{singlespace*}
\textbf{#1}: \emph{#2}
...
1
vote
1answer
87 views
some \newcommand instructions not working
I have created some new short command using \newcommand in the following example:
\documentclass[12pt,twoside,a4paper]{book}
\usepackage{enumerate,amsmath}
\newcommand{\ba}{\begin{array}} ...
1
vote
1answer
23 views
Error in PSTricks in circuit macros
I am trying the same way to use circuit macros through the example from Mr. Peter Jan Randewijk (http://staff.ee.sun.ac.za/pjrandewijk/wiki/index.php/M4_Circuit_Macros). I have installed M4 support as ...
4
votes
3answers
131 views
Arguments to Commands: […] vs {…}
Perhaps this is something that has been answered before, but a cursory search didn't turn anything up.
Is there any logic to how commands take arguments? Some things want the arguments to the ...






