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

4
votes
1answer
134 views

Command to count characters in a specified string

Is there a way to count the number of characters in a specified string? Suppose I had the following code. \documentclass{article} \newcommand{\numchars}[1]{\noindent The string ``#1" has ? ...
4
votes
2answers
45 views

Defining own command

I'm trying to create a command to save me some heartache when writing the rest of this document. What I'm attempting to do is to create a command like \double{-}, which when used will produce: ...
4
votes
2answers
22 views

Delayed expansion of StrSubstitute argument with active characters

This is an extension of my previous question. The accepted answer provided a way for me to delay expansion of a marked-up easylist list until the string was processed inside the environment. I'm ...
4
votes
1answer
43 views

Command doesn't expand into other commands after string substitution

The MWE should explain it all (use LuaLaTeX): \documentclass[11pt]{memoir} \usepackage[T1]{fontenc} \usepackage{fontspec} \usepackage{xstring} \usepackage{easylist} \begin{document} ...
0
votes
0answers
40 views

Formatting multiple-choice questions

I require a question environment with the following characteristics: The prompt has to be set beforehand with \prompt{What is the answer?} because the environment has to accomodate other data such as ...
6
votes
2answers
78 views

Iterator-like command, where each use expands to an item from list defined earlier

What is the simplest way to create an iterator-like macro (in the functional programming sense) in pdfLaTeX? I'd like to predefine a list of elements (to simplify we can assume that it is plain ...
5
votes
1answer
34 views

Replacing an id (integer) with a string?

I have a tex document that contains sections that are automatically generated. These sections have strings that are observation IDs. I would like to have latex replace all occurrences of an ID with ...
3
votes
3answers
45 views

Creating a new list Environment, how to change the length of \items

The code for the environment is bellow, For the longer lines in \list item how do I change the length of the \items so that it lines up with the date? Basically I want a kind of "margin" that is on ...
0
votes
2answers
72 views

Redefining math symbols like \eta (with ensuremath)

An easy one: I would like to define a shortcut so that I can write \eta without having to enclose it in $\eta$. However, the naive approach will not work: \documentclass{article} ...
3
votes
1answer
39 views

Creating a command within a list

So I'm trying to create a simplified kind of list inside of an environment, so that calling one command will create an enumerated item and calling another will create a subitem. Here's my code: ...
5
votes
1answer
46 views

Why am I getting an error when using \renewcommand, here?

I try to type \renewcommand{\mr}{\mathrm}, so that I can then use \mr in my text instead of \mathrm. I get the error \mr Undefined. what is going on?
5
votes
2answers
95 views

Defining a command and its starred version with different number of arguments

I want to create the commands: $\vecbi*{A}{s}$ and $\vecbi{A}$ To write bold vectors in my text. However, I have tried the following code, but I am still stucked without a solution. \makeatletter ...
4
votes
1answer
41 views

problem with newcommand with line break \\ and tabular inside

I define a new command \nonBranchingRule that takes 3 arguments. Intuitively, it defines a rule where the last argument is a comment (optional argument) for the rule. I want to place the comment under ...
0
votes
0answers
27 views

Remove italic style when using newcommand [on hold]

Whenever I create a new command the text (as a string) displayed by the command is italic. A simple command: \newcommand{\helloworld}{Hello world!} results in Hello world!. Is there some way to ...
2
votes
2answers
55 views

new command definition brings extra space

Sorry for my original example code can not relect exactly what I mean. I have made a new one. I am trying to define a new command, but it seems some unwanted extra spaces are generated together. ...
11
votes
3answers
307 views

Explain this macro: double hash with no number, \ialign

This macro is quite old, and I don't know plain TeX very well. MWE: \documentclass{article} \setlength{\unitlength}{0.06em} \newlength{\cellsize} \setlength{\cellsize}{18\unitlength} ...
3
votes
1answer
48 views

Parse numerical value from glossaries variable

Can I parse the text returned from \gls*{...} and get latex to recognize it as a numerical variable so that I can use it in a calculation? This calculation could be done using calculator, fp, calc or ...
2
votes
1answer
32 views

Count and Show Compile Error

\documentclass{article} \def\ad#1{$^{#1}$} \def\aff#1{$^{#1}$} \def\address#1{#1} \def\dept#1{#1} \def\inst#1{#1} \def\cyname#1{#1} \def\country#1{#1} \def\pcode#1{#1} \def\stname#1{#1} ...
2
votes
0answers
42 views

How can I “outcompile” macros?

Let's say I have have the file asdf.tex which contains the code: \documentclass{article} \newcommand{\asdf}{blabla} \begin{document} \asdf is very cool! \end{document} How can I compile my ...
3
votes
1answer
30 views

macro (newcommand) Why some text is not getting in the output ?

I want to repeat some text and tables on the same page. I am trying the code given below, but it is printing only once and then again it is not printing the ruler at the end. The complete code is ...
4
votes
2answers
45 views

Using \not command with custom-made ones

Task is simple. I have a command (alias of sort of a complex expression. I'm using frequently), and sometimes I'd like to put \neq instead of \eq. I can simply add third arg with default value, but ...
3
votes
2answers
85 views

Substitute string that contains a backslash

I need to create a function that will transform a string such as: Hello\textbackslash{}Bye into this: Hello \\ Bye I have tried using StrSubstitute (from the xstring package) without success. I ...
1
vote
1answer
34 views

Access specific glossary fields without triggering first usage

I would like to know if any of the fields that are manually configured during the creation of glossary entries can be accessed manually/deliberately in a macro or newcommand - possibly of the form: ...
4
votes
1answer
47 views

How to programmatically comment out environments?

I write multiple-choice exams using the Exam class and I would like to be able to print the exam without printing the answer choices. At the moment, I manually comment out everything from ...
0
votes
0answers
14 views

\newcommand to remove text and replace it by “empty” text [duplicate]

I am defining a command \newcommand\delete[1]{\text{}} % delete to replace a block of text in my latex document. It works almost fine, except that it inserts a space instead of "nothing". To be ...
8
votes
2answers
57 views

Splitting macros to individual tokens/characters, with catcode (to debug conditionals)?

Consider this MWE, modified from ifthenelse equal string comparison fails: \documentclass{article} \edef\test{german\relax} \edef\curentry{\string german\relax} \typeout{test: \meaning\test, ...
10
votes
1answer
399 views

Create a date X years later than today

I am trying to create a date X years later than \today. My dates have the following format : dd/mm/yyyy. I tried the advdate package, yet when the month is in [1-9] range, it returns the number of the ...
3
votes
2answers
43 views

Adding \comment or \begin{comment} to \AtBeginDocument?

For Partial compilation commands/environment?, I would like to add \begin{comment} or \comment at the start of the document (so I could turn it off elsewhere in the code). So, even if in the larger ...
4
votes
3answers
82 views

How to define _or_ redefine a command (mixing \providecommand + \renewcommand)?

In some situations I wish there was a way to define a command \tmp so that if \tmp does not exist: Defined \tmp if \tmp does exits: Redefine \tmp My current approach is simply to use either ...
4
votes
1answer
69 views

Use newcommand in newenvironment

I want create an environment with newenvironment which does the follow: it evalutes its height and print it many times (textheight/height) to fit one page. My first step: \documentclass{article} ...
10
votes
1answer
94 views

Use luatex to \let command to other

still looking for LuaTeX, I understand how I can execute Lua code insided TeX code (via \luadirect) but not how I could execute TeX code inside Lua code. I explain : I would like to make a series of ...
4
votes
2answers
73 views

newcommand: passing coordinates as a single argument

Is it possible to pass an array argument to newcommand and then access those individual array elements? For example, if I wanted to multiply the third element of the array (first argument) by the ...
12
votes
3answers
197 views

Assertions in Latex

I am writing a long latex document and use many macros for defining mathematical symbols. I would like to ensure that there is no clash in the notation. For example, something like ...
1
vote
0answers
131 views

Compiling tex file using pdflatex and cmd - strange behavior

I'm have a really strange problem here. I have a tex file which I compile to a pdf file using the pdflatex.exe which comes with MikTeX. The Problem is now that it seems a problem when the tex-file ...
1
vote
1answer
27 views

Expand macro at call site only

I want to draw a tree where each edge has a certain weight visualized through both the line width as well as a label on the edge. Using TikZ, this is pretty easy: \documentclass{standalone} ...
5
votes
1answer
130 views

Return Real from Macros

I want to build macros that return real values. For example, I would like to have something like following pseudo-code: \documentclass{article} \usepackage{etoolbox} \usepackage{calculator} ...
5
votes
1answer
39 views

Setting a specific key (and value) depending on state of \if macro

This question is basically a follow-up of two older questions I posted a year ago, but actually is a consequence of trying to find a solution to this question: Use toggles in biblatex ...
7
votes
2answers
59 views

Transform \sepfootnotecontent into an environment

I am currently cleaning the code of a 1000-page book that contain hundreds of very long footnotes so I decided to move them into separate files using the sepfootnotes package. It’s easy to use: ...
1
vote
1answer
45 views

How can I create a command or environment that starts and stops verbatim?

I am writing a simple LaTeX guide, aimed at editors of a student paper. The paper is for students of mathematics and physics at my university, and so we use LaTeX. Anyways, I want to include lots of ...
1
vote
0answers
34 views

endfloat and \newcommand incompatibility

I have a lot of figures and tables defined using \newcommand{\NAMEOFTABLE}{\begin{table}...\end{table}} and I would like to use them with endfloat package. Here is a MWE that demonstrates the ...
2
votes
1answer
55 views

Command not redefined

I am writing a custom package and would like to set the fraktur Real and Imaginary symbols to the standard \mathrm{Re} and \mathrm{Im}. I am trying to redefine them the standard and recommended way ...
11
votes
1answer
130 views

Why this output using \string on the empty csname

How does this exactly work? \expandafter\string\csname\endcsname I don't know what I would expect to come from there, but definitely not \csname\endcsname_ where _ is a space. I thought ...
1
vote
1answer
45 views

Compiling error after I comment a meaningless statement

I am making a multi-language document. With the big help of Mr. Steven B. Segletes, I am able to deal with several languages mixed document, which can only output in wanted one or several laguages. ...
2
votes
1answer
31 views

Guides to Writing Macros with Error Message

I'm trying to write \newcommand macros that will check the user's inputs to arguments and return an error message if an error (for example, value out of range) is found. Is there a good reference? ...
3
votes
0answers
38 views

Aliasing a variable argument command into tabular enviroment

I am making a multi-language document. With the big help of Mr. Steven B. Segletes, I am able to deal with several languages mixed document, which can only output in wanted one or several laguages. ...
7
votes
3answers
320 views

howto convert roman into arabic numeral

I know that there is a command \romannumeral that converts numbers in roman numeral \romannumeral3 gives iii Is there a converse like \arabicnumeral{x} that should produce 10?
6
votes
2answers
210 views

Spaces added to occurrences of “{}” in the TeX code

Can anyone explain how to get rid of spaces that are automatically added around arguments provided in curly braces in the main part of a text? Here's a minimal example: \documentclass{article} ...
1
vote
0answers
45 views

Write a class with different code for different version

I want to write a report-like class (maybe based on KOMA-Script). My problem is that the layout will be evolving and maybe the features of the package to. I would like to know if there is an easy way ...
2
votes
1answer
49 views

Use macros within listing

I would like to use I macro I have defined (including mathematical symbols) within a listing environment. However, the following code prints "\foo{x}" rather than "bar(x)". Is there any way of ...
5
votes
2answers
171 views

Redefine \emph to be both bold and italic

I'm trying to redefine the \emph command to make text bolded in addition to being italic, but when I use \newcommand{\bfemph}[1]{\textbf{\emph{#1}}} \renewcommand{\emph}[1]{\bfemph{#1}} I get an ...