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

22
votes
1answer
652 views

I need to write extra version for blind people without braille

I am writing a small math script and I also need to make version for blind people, but without braille. For example \frac{1}{2} shouldn't be literal fraction, but it should be 1 over 2. Can I override ...
5
votes
1answer
107 views

Resize tikzfigure in tcolorbox depending on height of tcolorbox

in my book I got many different type of boxes so I made some macros placing the boxes automatically according to their arguments. That's one of them. So far I made some boxes that have big "+" and ...
3
votes
2answers
71 views

Generate comma separated list with some non-empty strings

I'm trying to generate a comma separated list that uses strings that may or may not be empty. For example \mylist{\stringA,\stringB,\stringC} would expand to A, C if B is empty or B, C if A is empty, ...
0
votes
2answers
72 views

! File ended while scanning use of \@xs@testcase

my script produces this error: Runaway argument? \section *{Serumnatrium} \par \ib {Zweck}{ \el { * Wasserverteilung *\ETC. ! File ended while scanning use of \@xs@testcase. <inserted text> ...
2
votes
1answer
42 views

Can I count text as another category using TeXCount?

I am using TeXCount to perform a word count. I am using %TC:macro \macroname n (http://app.uio.no/ifi/texcount/faq.html#newmacro) to treat macros differently (for example I have a 'to-do' macro). Can ...
5
votes
1answer
73 views

Reduce source code of different tcolorbox macros

in my book I have a lot of tcolorboxes to use. They are slightly different so I added a macro that decides depending on the arguments, which tcolorbox to draw. Obviously that produces a LOT of source ...
4
votes
1answer
40 views

Large bibliography and local entries - Macro

I'm working on a (very) large document and I'd prefer to define my biblio entries as close as possible to the text I'm working on. Therefore, I'm using the "filecontents" package, to define separate ...
3
votes
1answer
67 views

convert string to active character

in my book I will have to itemize a lot of things in different lists. That's why I want to reduce my commands to a minimum. This script is just part of a bigger macro. \documentclass{book} ...
6
votes
2answers
171 views

How to rewrite this command using \newenvironment?

I once defined a customized latex command, which works well. And now I would like to convert it into a latex environment using \newenvironment command. However, I failed after trying several ways. ...
2
votes
1answer
25 views

How to pre-evaluate commands that are problematic for a specific environment?

More specifically, my problem occurs in the caption environment, but I imagine this applies elsewhere. I would like to insert the text generated by \suppOrApp and store it in the variable \sOrA: ...
4
votes
2answers
137 views

About \def\b*{\begin{align*}}

I want to make the code shorter. I defined the following pair of macros: \def\b*{\begin{align*}} \def\e*{\end{align*}} My point is that I saw this is a document, with \def\b*{\begin{eqnarray*}} ...
11
votes
1answer
100 views

What does \def\foo#{…} mean? [duplicate]

I came across this idiom recently: \def\foo#{...} That is, a hash but no parameter number. What might be the purpose of this?
2
votes
2answers
50 views

Multiple index keywords in a row

Is there a way to declare multiple \index{}keywords with a single command, instead of declaring them separately? More precisely, instead of doing \index{keyword1}, \index{keyword2}, ...
2
votes
1answer
97 views

Writing macros for tikz-cd arrow options

I'm trying to write a macro to let me write shorthand for tikz-cd arrows. For instance instead of having to write out the full command \arrow[swap, dotted]{r}{f^*} I'd like to have a shorthand ...
10
votes
3answers
707 views

Found it tiring to type so many \begin and \end

Is there some way to get rid of the \begin and \end's? For example, I need to type a small matrix, but I should type \begin{matrix}...\end{matrix}. I tried to define a macro ...
1
vote
0answers
19 views

Why is space inserted at beginning of table or figure caption when using macros to define caption label? [duplicate]

Here is my MWE. As you can see, the problem only happens when we use the macro \suppOrApp. \documentclass{article} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{caption} ...
0
votes
0answers
30 views

How to let latex only run one user defined command and save the ouput to a tax file [duplicate]

I want to let latex only run one of my defined commands and output results to a tax file. For example, the following tex file: \documentclass{article} \usepackage[usenames,dvipsnames]{xcolor} ...
5
votes
2answers
125 views

Loopy newcommand causes hanged processing

By a too quick search/replace of "mathcal" by "mc" I ended up with a loopy or recursive statement like \newcommand{\mc}{\mc} It seems to cause the compilation of my document to hang. Is this a ...
3
votes
1answer
71 views

LaTeX Macro for “code” style, underscore package and hyphenation

I'm looking for a way to nicely set code inside my document. I used \def\code#1{{\texttt{#1}}}, but it still allows the text to be hyphenated. To prevent that, I tried the advise from Prevent ...
5
votes
1answer
118 views

Latex \newcommand with python code inside

I'm extremely new to Latex. I'm using python package to insert graphics in a loop. What I can not understand is how I can transform this code \documentclass{article} \usepackage{python} ...
9
votes
2answers
109 views

Error when using defs inside a macro to write a row in a table

For the following MWE \documentclass{article} \newcommand{\cmd}[5]{% \def\tA{#1}% \def\tB{#2}% \def\tC{#3}% \def\tD{#4}% \def\tE{#5}% \tA & \tB & \tC & \tD & \tE \\ } ...
7
votes
2answers
158 views

Using commands inside \url?

How does one use commands inside \url{..}? MWE: \documentclass{article} \usepackage{textcomp} \usepackage{xcolor} \usepackage{url} ...
1
vote
0answers
29 views

replacing macros parameters by its definition [duplicate]

Usually, I use many macros in my documents to save time. I am searching for clever "ideas, methods, tools" which can replace macros by its definition. For example, if we have a the following document ...
3
votes
2answers
115 views

defining macros in lyx

I am having a problem defining a script that I got as a macro in LyX (or even making it "work" in LyX). The script I have is the following: ...
17
votes
2answers
233 views

Can I turn a collection of optional parameters into a macro?

I currently have several environments from mdframed that have a large number of options that are shared between them. The situation looks like \newmdtheoremenv[options0,options1]{env1}{Environment 1} ...
1
vote
0answers
27 views

Can I use Writer2LaTeX and the `mla-paper` style together?

I use LibreOffice 4.1.3.x, and have had success using a patched version of Writer2LaTex with documents created in LibreOffice Writer. I want to create a (sub?)filter for Writer2LaTeX that allows me ...
1
vote
1answer
79 views

Cite Command with a Customised Field for Biblatex

I am writing a PhD and my mentor wants me to use a specific short form of citation in the footnotes and long one in the bibliography at the end of the work. So basically I need to have three short ...
2
votes
1answer
100 views

Hacking into (internal) references in exam class

So far, I have used my homebrewn style file to create the examination papers which have multiple sets of questions. Recently, I switched to the exam class and immensely enjoying the additional power ...
5
votes
1answer
281 views

Putting normal letters in between Greek ones

So I am trying to write out Gauss' law for gravitation and I am having a hard time figuring out how to write it out without an error. I am currently trying to write in an equation block ...
6
votes
1answer
59 views

Conditional based on character following the macro

Basically, I would like to something like \xspace does, i.e. the meaning of the macro should depend on what is following it. So for example if I say \mymacro a it might expand to foo, and if any ...
13
votes
1answer
265 views

How to execute a command only on the next run?

Let's say I have a command \foo that I want to execute only on the next run of TeX. How do I create a command \onceFoo that does this? (It is also permitted to execute \foo if the aux file has been ...
2
votes
1answer
201 views

Error: Command \ invalid in math mode

I am getting the following error: Command \ invalid in math mode. Why? Compilation ends but no PDF is created because of those errors. This seems to be the problematic piece of code but I don't ...
3
votes
1answer
66 views

Why doesn't TeXstudio produce {} for my custom commands?

I'm having the following problem in TeXstudio 2.7.0. I have a template where I've declared some custom commands, such as \newcommand{\myAnswer}[1]{ \begin{itemize}[leftmargin=*] ...
6
votes
1answer
178 views

Why \shorthandon and \shorthandoff cannot be embedded in other macros?

Surrounding \title macro with \shorthandon{;:!?} and \shorthandoff{;:!?} gives the expected result with babel's french language (space added before the '?', '!', ':' and ';'): ...
3
votes
1answer
64 views

bibtex ignores MACROs in bst style

So I created my custom bst file using "latex makebst" it mostly works fine and I slowly get a rudimentary hang how the .bst thing works. Mostly thanks to this guide ...
3
votes
2answers
189 views

Combining two custom commands

I came across a problem when typing my report. I do not know how to fix this. The problem is as follows: I have two custom commands defined like this: \newcommand{\slr}[1][n]{\ensuremath{{\bf ...
3
votes
1answer
54 views

How can I use adjustbox in \sectionmark?

I want to use adjustbox in \sectionmark but it doesn't work. Is there a work-around for this? \documentclass{book} \usepackage{blindtext} \usepackage{adjustbox} \usepackage{fancyhdr} ...
1
vote
2answers
119 views

Semantic indications in LaTeX

I'd like to include in my LaTeX code some form of indication that certain words are keywords, or that a phrase is a quote, or that another phrase is an example, etc. Where can I find a list of inbuilt ...
4
votes
2answers
121 views

Remove macro's functionality via a regular expression

I want find all \textbf in my .tex file and delete it, together with it's argument braces {}. For example, I want to change: \textbf{text} to text \textbf{text \textit{textbis}} to text ...
2
votes
0answers
56 views

\ref to \label in other document?

I have a repository with one document, but I think of splitting it into two documents, whereas I want to cross-reference from one to eachother. Is there a way, to "rewrite" \ref to automatically ...
2
votes
1answer
49 views

Define reusable content — preferably in the body or else in the header

I am writing a document where name of a person A will appear at multiple places section A. Similarly, name of person B will appear at multiple places in section B, etc. Is there any way by which just ...
1
vote
0answers
94 views

Make References title bold in apa6 class document (using natbib) [duplicate]

I'd like the References title to be bold. My MWE is below. If you comment-out the \usepackage{natbib} (and following line) the problem doesn't occur. Assuming natbib is causing this, I thought adding ...
2
votes
1answer
48 views

Using argument command as argument without brackets

I would not be surprised if this has been asked before, but my searches did not yield any results. Neither would it surprise me if this is not possible without doing some really dangerous hacking of ...
4
votes
1answer
40 views

Aliasing, with or without argument?

What is the correct way to alias a command to another one? \newcommand*{\keyword}{\emph} or: \newcommand*{\keyword}[1]{\emph{#1}} Apart from the fact that the second is more explicit, is there ...
4
votes
1answer
54 views

Content summaries - sections

I'm currently writing up my thesis and I have a section "content summary" in my introduction section. This gives an indication to what each section contains and is about. At the minute, each chapter / ...
4
votes
0answers
58 views

Variable Input/Output node using a new command

How can I create a variable input/output node using a new command as in the following picture Say for example, I know that the node will have n inputs and m outputs, which I enter the name as an ...
4
votes
2answers
52 views

How to store the definition of a command? Or, how to disable locally a command?

what? I would like to "store" the definition of \includegraphics into \something so that the following logics will work: % the following line is what I am looking for store(\includegraphics, ...
0
votes
0answers
58 views

Macros for the subscript and spacing

I would like to define the command A\!\!_B\!C in a math mode as a macros, and I am using the following: \newcommand{\cmp}[3]{#1\!\!_#2\!#3} Unfortunately I get an error that there are {} missing. ...
7
votes
3answers
151 views

How to horizontally align rotated text in a table?

I am trying to horizontally align text that has been rotated in a table. I want the rotated "Lorem Ipsum" and the rotated "Lorem Ipsum & Lorem Ipsum" text to be horizontally centered in the cell. ...
5
votes
2answers
267 views

how to redefine environments like \begin{xxx} … \end{xxx}

I'm translating some text that use the comment package, it's usage seems like that: \begin{en} ... some English text \end{en} \begin{zh} ... corresponding Chinese text \end{zh} By using ...