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

custom hatching pattern : arbitrary direction of hatching

For a kind of mathematical illustration, consider the case where several distinguishable hatchings, all black and white, and precise direction has meaning, are required. I give a simple example of a ...
2
votes
2answers
109 views

“Undefined Control Sequence” error despite \newcommand definition!

I have installed texlive full package: I use TeXmaker and this is a code where I want to draw a grid as in tikzpicture. I want to just call the \gridkar function defined below. So I defined it in ...
3
votes
2answers
39 views

Compiler Error when Creating a Macro/Environment

I'm trying to create a new command or environment or something to format what is essentially a section, but it needs to have it's own counter. I would like to not use any of the \section \subsection ...
5
votes
1answer
52 views

Problem with underscores in \newcommand

I am currently writing my thesis and I have each chapter as a separate project- I've been told I should join them up but I don't want to for now as I would find it overwhelming. I'd like to be able to ...
1
vote
3answers
108 views

Parse csv-list, function with >1 parameters as callback

In my texts I have to deal with lists, whose items need to be formatted seperatly, i.e.: \funktion[3][]{T}--\funktion{S}--\funktion[3][7]{D}--\funktion{T} In \funktion which leads to \emphsubsup the ...
6
votes
1answer
117 views

Defining a new command works selectively

I have just created a new command that will print text in bold and blue using the following syntax \newcommand{\blue}[1]{\color{LHCblue}{\textbf{#1}}} My full code is ...
1
vote
1answer
66 views

“Theres no line here to end” in custom command

I am working on creating a resume in LaTeX and have defined a command that allows me to input my work experience. The only problem is that whenever I try to use an itemized list, as seen below, I get ...
4
votes
2answers
52 views

Using forcsvlist with macros that take more than one argument

I'd like to compact this code sample with \forcsvlist (provided by the etoolbox package). \newcommand\mycmd[2]{ \pagestyle{#2} \csname tit#1\endcsname \cleardoublepage } \def\DOtitlepages{ ...
3
votes
3answers
75 views

\input{} as argument for \inputgraphic{}

I got a question very similar to this post (\includegraphics{\input{|shell command}}) which unfortunately hasn't been really answered. The aim is to make a command that invokes a python script to ...
4
votes
2answers
65 views

Add content from an external file to the input tokens for parsing

I have a possibly very long sequence of tokens which is parsed by a macro. I would like to be able to read parts of this sequence from external files, if this is possible. I made up an MWE for this ...
2
votes
1answer
28 views

How can I apply a custom-defined theorem environment to nested theorems *only*?

In a previous thread, I asked about the possibility of defining a custom theorem environment whose QED symbol would be a boxed version of the theorem's name/number/label. There, I was graciously ...
9
votes
2answers
202 views

How to use \csname, \expandafter, \csuse, \@namedef …?

I have the following package \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{mypkg} \providecommand*\@mycmd{No {\MakeUppercase Mycmd} defined} \newcommand*\Mycmd[1]{\renewcommand*\@mycmd{#1}} ...
2
votes
2answers
74 views

Defining New Environments using a Command

I would be able to do something like the following: Instead of having the following, where I repeat the same code many many times: \documentclass{article} \usepackage{enumerate} ...
0
votes
1answer
155 views

Why does LaTeX macro spells \LaTeX{} (which requires Shift) and not \latex{}? [closed]

Why does LaTeX macro spells \LaTeX{} (which requires 3x presses and 2x releases of Shift) and not \latex{} (which can be typed w/o Shift)? Same about \TeX{} macro of course. The current spelling ...
2
votes
1answer
56 views

How to check if a macro from <some package> is used in a document?

I was interested in some method to check if any macro from some package is used into a .tex file. So, for example I would like to specify a package (say it's fontawesome) then point to a .tex file ...
4
votes
3answers
71 views

Newline is not working with parbox and usebox

I would like to save data to a savebox (or any other storage element) in iterations. At the end I would like to put each datapoint in a framebox and then in a frambox container with a given width. ...
0
votes
0answers
29 views

Can't make unit vectors with greek letters [duplicate]

I have this command \let\oldhat\hat \renewcommand{\vec}[1]{\boldsymbol{\mathbf{#1}}} for making bold vectors. And have this commands here \newcommand{\uvec}[1]{\hat{\textbf{#1}}} ...
8
votes
2answers
99 views

Why is the character following this macro-defining macro gobbled up?

I have the following plain Tex code: \def\xx{ABC} \def\temp #1 {\def\tempii{#1}} \temp\xx a b c \tempii\tempii I expect to see the following output: a b c ABCABC But I actually see this: b ...
3
votes
1answer
40 views

Add newcommands to a package with arguments

I want to make a package that has a bunch of commands that I define in all of my Problem Sets. I'm running into an issue where the compiler does not recognize commands that I define that have an ...
2
votes
1answer
79 views

How to load user defined content to be used in a template?

I'm writing a template which uses the report class and customizes the typesetting with several packages. I'm defining some data in a separate user-data.tex file which is loaded just after ...
5
votes
1answer
301 views

destructive code by style file

I'm making a certain program, which is calling LaTeX. I'm thinking that this program can include only one style file. My question is "can we write destructive code in style file?". For example, can ...
9
votes
2answers
148 views

Macro to add starred version of command

How can one write a meta-macro that adds a starred version to a command? Intended use would be along the lines of \newcommand\foo[1]{foo is #1} \addstarred\foo[2]{foo is #1, bar is #2}
0
votes
2answers
42 views

Redefine \chapter and \chapter* with \cleardoublepage inside .cls-file

\newcommand{\Chapter}[1]{{\let\cleardoublepage\relax\chapter{#1}}} works fine. How can I do the same for the stared (*) version inside a .cls-file? (Could be interesting for others: Is there any ...
3
votes
1answer
28 views

macro with optional argument in eforms textField

This is my code: \documentclass{article} \usepackage{polyglossia} \usepackage[useui]{eforms} \newcommand{\myvalue}[1][]{Testvalue #1} \begin{document} ...
5
votes
2answers
85 views

Matrix of values as parameter for a macro

This is my code: \documentclass{article} \usepackage{polyglossia} \usepackage{forloop} \newcommand{\values}[2]{ \ifcase#1% \ifcase#2% value a% \c% value ...
6
votes
2answers
170 views

Space between commandname and argument-braces

Simple question, maybe duplicate but can't find it. I see some people (especially novices) writing something like \textbf {text} %or \frac {1} {2} It looks not good with the spaces between the ...
1
vote
2answers
72 views

Macro indent line even on newline

I'm new to creating my own commands (this is my first) and I can't seem to achieve what I set out to do. My current command looks like this \documentclass{article} \usepackage{xparse} ...
21
votes
3answers
605 views

How to make a command completely empty / invisible / non-existent?

I have a command like \newcommand{\todo}[1]{#1} which I sometimes replace by: \newcommand{\todo}[1]{} In terms of spacing/whitespace, the behavior of the "empty" command is as follows: Test. ...
5
votes
3answers
178 views

Defining a command with variable number of primes

I want to construct a new command which allows me to write somthing like: \env{3} Which would then expand to: σ''' I.e. a sigma with the specified number of primes. I however have not been able ...
3
votes
2answers
35 views

Page break after each section with title

I'd like to have there be a page break in between each section, just like in this question, but I'd also like there to be no page break prior to the first section (that is, between the title and the ...
7
votes
2answers
100 views

Define a macro changing category code of number sign (namely \makenumbersignletter)

Under Typesetting hashtags with natural syntax Joseph Wrigh ask me to ask a new question: In LaTeX, \makeatletter is short for changing the category code of @. But something like ...
22
votes
5answers
705 views

Typesetting hashtags with natural syntax

I'm using an online conversation in my document and I've made an environment to use for it. The thing is, there are many #hashtags in each post (that I'd like to color appropriately). To make it ...
3
votes
1answer
67 views

ConTeXt: Macro within macro for URLs

Background Would like to define a base URL that can be reused by other macros. Problem Using the \goto macro requires a fully expanded URL. Minimum Working Example Here's code that illustrates ...
17
votes
1answer
244 views

Why doesn't \makeatletter work inside \newcommand?

After hours of banging my brain against my skull, I narrowed down an issue I'm having to the fact that \makeatletter doesn't work inside \newcommand. Commands that I call after \makeatletter are ...
2
votes
1answer
54 views

Using \newcommand with arguments inside of \newcommand

I'm using the following commands inside my main TeX file right after the ToC. \mainmatter \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}} ...
8
votes
1answer
112 views

Defining a command that scans every arguments' macro “looking for” a token

Knowing that every command declaration with conditionally optional arguments, as \foo{...} expanding into \foo[default]{...} can be defined by \newcommand\foo[1][default]{...} or the safer version of: ...
8
votes
4answers
183 views

Tex capacity exceeded by using renewcommand to add arguments into a list

I was working on a small macro in which I create a \newcommand with two arguments. The second argument is just a name. I want to use this \newcommand more than once and at the end I would like to have ...
3
votes
1answer
64 views

Expanding parameters inside \csname

I've browsed every question I can find on \csname and I see lots of code that uses it inside a macro and passes the arguments inside to be part of the name, but only when defining a macro. I need to ...
1
vote
0answers
33 views

textual replacement within spreadtab

similar to this question I want to use a function inside of a spreadtab region, but i do not want to use it out of a seperate file but just simplify the usage and readability. Unfortuntely the usage ...
5
votes
1answer
63 views

Defining a command that conditionally defines/checks for counters

In order to complete one custom package command I needed an internal macro, I called it \@test@count{❬argument❭}, and should accomplish the following: Internally defines a new counter \❬argument❭ ...
3
votes
0answers
50 views

Retrieving coordinates of every character in a formula

I'm writing a program that uses LaTeX to display formula's. The user must be allowed to click on different parts of the formula, and the program should know on which part the user clicked. Is there ...
3
votes
1answer
26 views

How to properly expand an argument to the \url or \path macro?

In the following MSE: \documentclass{article} \usepackage{url} \newcommand{\rootDir}{\$ROOTDIR} \newcommand{\myDir}{my/dir} \newcommand{\makeFilePaths}[3]{% ...
4
votes
3answers
214 views

How do I make \dots more compact? Or are there alternatives?

How would I go about changing the \dots command to be more compact? I would like the dots to be closer together so that the printed symbol takes less horiontal space. Alternatively, does anybody know ...
3
votes
2answers
61 views

Section and newcommand in LaTeX's memoir

I want to change the section layout. The section layout should start with an § then the number (which should start with 1 instead of 0.0) and then the name of the section. I have tried to make such a ...
4
votes
1answer
73 views

Write multiple pdfs with different options

Thanks a lot for the help in advance. This might be a stupid question, or a potential overkill for this kind of forum, but the situation is as follows: I'm writing my dissertation and - of course - ...
3
votes
1answer
37 views

verbatim text in tables and macros [duplicate]

I have a cheatsheet with a table that looks like \begin{tabular}{l|l} $k > 0$ & \verb+k > 0+ \\ $k \geq 0$ & \verb+k \geq 0+ \\ $\sum_l$ & \verb+\sum_l+ \\ %etc ...
4
votes
2answers
146 views

How can I automatically replace subscripts and highlight GoTo labels?

I have to show a lot of autogenerated code throughout my document. The generated code represents loops with explicit block labels and gotos. The following code applies function f to each element of ...
3
votes
2answers
127 views

How to calculate and use the ratio of two lengths?

I want to calculate the ratio of two lengths in Latex, so that I can then stretch an en dash by that ratio. For example, in the code below, I'd like to replace the "0.7" value of FakeStretch with the ...
10
votes
1answer
127 views

Macro parameter delimited by more than one delimiter

TeX user can simply create the macro with a parameter delimited by an arbitrary sequence of tokens. For example \def\macro #1delimiter{...#1...} Is it possible to create a macro with a parameter ...
7
votes
3answers
201 views

Replace instances of \cite that have a specific argument

In LaTeX, is there a way to define a macro (or something) to replace every instance of \cite{a_literal_string} with \ref{appendix:a_different_literal_string} without touching instances of \cite ...