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

6
votes
2answers
494 views

Using xstring to check .tex file name

I am having difficulty in using xtring to check the file name of the .tex file. All three of the cases shown below produce the wrong output. Surprisingly in my actual more complicated usage, the ...
4
votes
1answer
670 views

How to treat the arguments of a macro as literal or verbatim text?

I'm working on a package that allows Python code to be entered within certain commands and environments, saves the Python code to external files and executes it, and brings back the results via \input....
10
votes
2answers
615 views

Is it worth defining \ensuretext ?

We already have \ensuremath to make sure the argument get enclosed in math mode. Is it worth defining \ensuretext ?
3
votes
3answers
959 views

Reduce Space Between Characters in New Command

I'm not satisfied with the new command I've made. My code: \newcommand{\ps}[2]{\mbox{P}_{#1}\left(#2\right)} $\ps{Y}{y}$ %example My problem is that there's too much space between the subscripted Y ...
48
votes
7answers
4k views

Short names for macros

Often it happens that I would like to define macros that I would use very frequently throughout the document – for example, a special symbol that I use repeatedly in many equations. Ideally, in such ...
30
votes
6answers
2k views

How do I typeset morse code with LaTeX

I am writing an article regarding the history of the Morse code and I am having difficulties printing the dots and dashed (they get combined when the document is printed). Is it also possible to ...
5
votes
2answers
879 views

Passing nodes as parameters to a macro in TikZ

I would like to define a macro which would take two nodes as arguments and "connect" them using a third, predefined node. Like this: \documentclass{minimal} \usepackage{tikz} \usetikzlibrary{shapes,...
12
votes
1answer
518 views

How do I check whether the text will fit in one page?

I am trying to typeset a page that varies in length. Sometimes it's just shorter than A4, but sometimes it exceeds the length of A4. My question is, how can I check whether the text will fit in one ...
6
votes
2answers
3k views

“Illegal parameter number” errors, in a macro for writing macro definitions to a file

Problem. I'm trying to write a command similar to \newcommand, but I'm having problems with illegal parameter numbers: for reasons that I can't fix out, it's asking me to use parameters of the type ##...
3
votes
1answer
2k views

Mathaccents, fontdimens, macros, oh my!

Why doesn't this work? \def\circacc{% \dimen0=\fontdimen5\textfont2 \fontdimen5\textfont2=-.5ex \mathaccent\circ \fontdimen5\textfont2=\dimen0 }$\circacc a$\bye The last line produces an ...
5
votes
2answers
553 views

Correct sorting of \index entries containing macros

I use \index in classical way, but also with some macros as content. More precisely, I have some macros like \def\foo{BAR}, and I use then \index{\foo}. Unfortunately, the index is then order by the ...
7
votes
2answers
762 views

Forcing tikz/pgf to expand macros within commands

I would like to use simple macros within tikz commands, but it seems tikz doesn't expand them in the ways I would expect. For instance, the code \pgfpointcurveattime{.25}{\pgfpoint{0cm}{0cm}}{\...
4
votes
1answer
515 views

How to adjust macro to respect current \linewidth?

I'm having issues with text going past the end of the specified \textwidth. I posted this question about why text was being placed beyond the specified line width. The MWE provided there produced ...
14
votes
2answers
395 views

Macro to take a character as argument, make it active, then \def it.

I have a XeLaTeX document in which I want some unicode symbols to be auto-substituted, like ¼ → 1/4, » → >>, « → <<. But instead of a long list like \catcode`\¼=\active\def¼{1/4} \catcode`\«=\...
10
votes
5answers
2k views

How to define a parshape command with LaTeX?

I want to typeset a book with some \parshape command, for example: \documentclass{article} \usepackage{lipsum} \begin{document} \parshape=4 0.2\textwidth 0.8\textwidth 0.2\textwidth 0.8\textwidth 0....
58
votes
5answers
7k views

How can I see the “implementation” of the \LaTeX command?

After reading another question relating to how to see definitions of commands, I tried: \documentclass{article} \begin{document} \show\LaTeX \end{document} But this shows me in my logfile: \LaTex=...
20
votes
1answer
7k views

Problem with \newcommand, no space after calling new command in the compiled text [duplicate]

Possible Duplicate: \newcommand and spacing In my latex document I have defined a new command to force a consistency in naming of a product I talk in my document: \newcommand{\fancyName}{\...
3
votes
2answers
1k views

Macro that inserts arguments into an environment

I'm having a bit of an issue trying to get a piece of code up and running. I'm working on extending python.sty file for embedding python into a LaTex document (adding persistent data and the ability ...
14
votes
3answers
836 views

Macro for a sequence of variables

Currently, I have a macro \bigseq which takes a variable name and a last number and produces #1_{1},#1_{2},\ldots,#1_{#2}, and for example x_{1},x_{2},\ldots,x_{n}. Now, sometimes I want to produce a ...
4
votes
1answer
1k views

Using Macro Defined Lists in TikZ/PGFplots

I want to be able to use a macro to specify a list (it is a constant list, i.e. will not change throughout the document) and use this macro rather than hard code the list contents in the TikZ/PGFplots ...
56
votes
3answers
7k views

\newcommand and spacing

How can I define my own shorthand command, but making sure that the spacing afterwards is correct? \newcommand{\abc}{\textsc{abc}} produces 'ABC,' but has the problem 'ABCmoretexthere' (i.e. no space ...
5
votes
1answer
372 views

Using \IfNoValueTF within a TikZ style specification.

In an answer to Flushing PGF commands and local variable Matthew had suggested using \IfNoValueTF within a TikZ \node specification to determine the text. This solution works great for me. However, ...
2
votes
0answers
316 views

Macros for et al, e.g., i.e., etc. [duplicate]

Possible Duplicate: Macros for common abbreviations Hi, Taking et al. as an example, is it possible to make a one-shot macro like \etal that can actually handle all possible cases where you'd ...
4
votes
1answer
355 views

How can I pass the body of a TikZ node to a font-changing macro?

After looking around at some other answers on this site, I'm trying to typeset a tree using the tikz-qtree package. It works great, but by design it does not let you use macros in the tree nodes, ...
11
votes
1answer
1k views

Conditional using non-integer numbers

I am trying to generate fractals using affine transformations. I need to generate a random number in the interval (0,1), and depending on the value of this random number choose a function to ...
4
votes
1answer
246 views

Determine if within a PGF axis environment

Is there an easy way to test whether a macro is called from within an PGF \begin{axis}...\end{axis} environment? One solution would be to define a new environment myself that sets a flag at \begin{...
5
votes
1answer
431 views

TikZ: pgfutil-common: pgfutil@in@ - how does it work?

Having been writing small lib for TikZ, I tried to use this macro in order to search for @. Code compiled, but the result was false, despite that I was sure it was in tested string. So, I decided to ...
21
votes
3answers
2k views

Is there a way to measure the remaining space of a line of text?

I'd like to write the following: Some long paragraph of text \measureremainder{\whatsleft}\begin{mimipage}{\whatsleft} stuff \end{minipage} so that the minipage takes up exactly the remaining \...
3
votes
2answers
334 views

Macro behaviour different inside tabular environment

I have a lot of problems lately with macros expanding (or not expanding) at unexpected times, so thought I was having a related problem here. But, in this case, things are working as I want outside of ...
7
votes
3answers
5k views

How to redefine the caption command with optional arguments

I'm writing a thesis that has double spacing on by default throughout the document. However, captions on figures need to be singlepaced. I can do that like this \normalsize \singlespace \caption{ ...
2
votes
1answer
1k views

How to pass a \def parameter to an inner command (StrSubstitute)?

I'm attempting to create 2 macros to simulate an array list as in Java for example. I'm using xstring StrSubstitute for this purpose, but I'm having a problem. Below is the code, it's a bit long as it ...
1
vote
2answers
438 views

Flushing PGF commands and local variable

I think I need a way to flush the PGF commands as the reference to \LabelText uses the last value, and not value at the time of invocation. The macro LabelPoint is intended to replace the first \...
2
votes
3answers
2k views

Any ideas why this \newcommand{\n}{\lstinline|\n|} macro doesn't work?

So I created a new macro \newcommand{\n}{\lstinline|\n|} but for some reason when I use it, all I get is bold 'n' letter and not a nice \n. Any ideas?
9
votes
1answer
532 views

Custom macro for multicolumn with & without xparse

The following example has two normal LaTeX \newcommand macros and two xparse \NewDocumentCommand for specifying multicolumn text. The only difference between each pair of commands is one has the ...
8
votes
1answer
204 views

Compressing a list

I have an application, where I am using lists to store reference numbers of forms as shown below: \alist(1,2,3,4,4a,8,9,10,23,23b,28) As these lists get rather long, I would like to compress them ...
3
votes
2answers
291 views

Macro with \n doesn't work, not sure why.

I created a macro called \code to wrap all the code fragments in my book, \newcommand{\code}[1]{\emph{#1}} But for some reason when I use this \code{\\n}, I never get the \n displayed. For some ...
4
votes
3answers
951 views

How to use \def or similar command to store an arbitrary number of variables for later processing?

I'm trying to create a package for drawing simple sequence diagrams using PGF/TikZ. Here is the basic idea I'm stuck at (not the whole idea to make it short): Let's say we have 1 environment (say ...
2
votes
2answers
3k views

Pass a command as argument for another command

Second question today: is there a way to pass a command as an argument of another method? \newcommand\foo[1]{Foo does: `#1'} \newcommand\bar[2]{Bar does: `#1{#2}'} ... \bar{\foo}{xxx} The output ...
1
vote
1answer
313 views

Passing listing-environment as option to command [duplicate]

I have a simple command which takes one argument. Now I want to pass a small listing-environment to the command. Here is the code: \documentclass{article} \usepackage{listings} \begin{document} \...
1
vote
2answers
152 views

Distinguish space (ASCII 32) and return (ASCII 13) in \def's arguments

A related question can see here. I want the \mydef behavior is \mydef{a b c d} get a correct export but \mydef{a b c d} or \mydef{a b c d } get a incorrect export (like a warning message).
12
votes
2answers
682 views

Restrict macro to an environment

I am quite a noob when it comes to customising LaTeX/XeLaTeX. I would like to know if there's a way to limit the usage of a macro to a specific environment. Consider the following macro and ...
9
votes
2answers
2k views

How to use the space for \def argument's separator

Assume there is a line including some single letter like A, b, C, etc. and the letters separate by only one white space, which ASCII code is 32, say, D B g A I want the content for a \def's ...
6
votes
1answer
1k views

How to capture the result of \StrSubstitute into a macro?

I have a macro, say defined as follows: \edef \temp{A.input 1} I want to replace the dot with hyphen and have the result being stored in \mystart. Something like that: \edef \mystart{\...
3
votes
1answer
389 views

tkz-euclide, define points outside of tikzpicture

Is it possible to define points in tkz-euclide outside of the tikzpicture environment? For example I would like to have something like this exercise in elementary geometry: Exercise: Consider the ...
5
votes
1answer
370 views

Test if text fits on one line

I have a boxed text that is justified, but I would like to make it centered if it takes only one line. Currently, once the text is rendered, I add a \filcenter as an option to my box macro, but I'm ...
3
votes
1answer
426 views

Use of \foreach and \csname<macro name>\endcsname together

When I compile this minimum LaTeX file: \documentclass{report} \def\defMacro#1#2{\expandafter\def\csname#1\endcsname{#2}} \def\useMacro#1{\csname#1\endcsname} \usepackage{pgffor} \begin{document} \...
29
votes
8answers
7k views

Repeat command n times?

Is it possible to define a command, which repeats the following command n-times? Call it for example \Repeat, then \Repeat[4] \command{...} should be equivalent to \command{...} \command{...} \...
3
votes
1answer
214 views

Basic xparse does not seem to be working

I can't seem to get basic xparse working. This seems like a bug, but this example feels so basic that I feel that there must be something I am not understanding about how to use this. Here is my test ...
7
votes
1answer
210 views

How to cache the results of a macro

TeX's ability as a programming language can be leveraged to produce documents that include fairly sophisticated calculations. Although not everybody's cup of tea, such documents are akin to literate ...
4
votes
3answers
2k views

Can (pdf)LaTeX recognize text strings and replace (expand) them?

I'd like LaTeX to replace e^ with \mathrm{e}^. I know I could just make a macro \e that does this, but I know I'll forget using it.. Can LaTeX find and replace and replace letter combinations (I don'...