Skip to main content

Questions tagged [def]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
26 views

Remove newline from input

Is there a way to remove a single newline character from an input? Something like this \edef\test{\removenl{ Hello World % }} % \test should have ` Hello World ` Context: Consider a file.txt that ...
Tohiko's user avatar
  • 1,833
2 votes
3 answers
263 views

Defining a custom if command

In the following minimal example, I am able to define a custom \if* command based on ifcsname, however when I use it inside \loop construct I get Extra \fi errors \documentclass{article} \...
Tohiko's user avatar
  • 1,833
2 votes
1 answer
103 views

Create new count with \def

I have the following macro/command: \def\definenewcounter#1{\newcount \csname#1\endcsname} It is supposed to create a new count with it's name being whatever argument 1 is, but it is throwing errors. ...
fsr_j's user avatar
  • 75
4 votes
2 answers
109 views

Redefine the command \cite to be able to use an additional syntax

Background The package amsrefs redefines the command \cite so that one can use the syntax "\cite{book-name}*{optional-argument}" to produce (essentially) the same output as the usual "\...
Lorenzo Pompili's user avatar
1 vote
2 answers
35 views

Weird Question with def, and condition

MWE: \documentclass{article} \def\ENLANG{english} \def\FRLANG{french} \def\LANG{\ENLANG} \begin{document} \if\LANG\ENLANG \ENLANG \else \FRLANG \fi \ifx\LANG\ENLANG \ENLANG \else \FRLANG \fi \LANG\ \...
Twilight's user avatar
0 votes
2 answers
59 views

def inside def gives an error when used with ref

I want to define a command that returns a label to use with \ref, but it requires using \edef to expand another command. However, I am getting several errors starting with Missing \endcsname inserted. ...
Tohiko's user avatar
  • 1,833
0 votes
0 answers
62 views

pandoc --metadata-file yaml on xelatex and debian - how to debug?

Please guidance and help. How can I debug a pdf generation from a latex template (using xelatex)? I am having trouble bringing metadata from yaml files, is there a way to see log, aux, out files when ...
Bruno Schroeder's user avatar
3 votes
3 answers
136 views

\def and \edef: Expansion for one level, not more

I want to save the content of a macro (which may contain text and other macros) for later use and without full expansion. \def\mcr{a} \def\textandmacro{sampletext \mcr} % this content i want to recall ...
coonlight's user avatar
  • 137
0 votes
0 answers
32 views

TikZ: collecting defined coordinates in a list

I want to collect previously defined coordinates in a list and print them later in a \foreach-loop for debugging purposes. The following MWE shows the list \points which ideally should be defined and ...
kaat0's user avatar
  • 1
0 votes
1 answer
56 views

Using \protect to generalise definitions of starred commands?

This very helpful answer led me to define my own starred commands. However, in order to use my commands in, for example, headings, after a round of strange almost frightening thoughts, I managed to ...
mfg's user avatar
  • 539
0 votes
2 answers
77 views

How do you create a variadic new command?

The word "variadic" is used for functions, and commands, which can accept any number of input arguments. Below, we see an example of a custom command which has three inputs: \newcommand{\...
IdleCustard's user avatar
  • 1,250
2 votes
0 answers
48 views

Problem with citation of authors having user defined command in their names

I have a problem using polski package simultaneously with imakeidx and biblatex. I only use the command \dywiz from package polski which is defined as \def\dywiz{\kern0sp\discretionary{-}{-}{-}\...
andc's user avatar
  • 961
4 votes
1 answer
324 views

How to get rid of \def

I was recently required by a journal to getting rid of \def in the definitions of my personal macros. It turns out to be not-so-easy and the naive replacement of \def by \newcommand does not always ...
Bazin's user avatar
  • 235
0 votes
3 answers
132 views

How to understand "\appendroman#1#2#3" on page 41 of The TeXbook?

At the bottom of page 41 of The TeXbook, there is a question: Define a control sequence \appendroman with three parameters such that \appendroman#1#2#3 defines control sequence #1 to expand to a ...
Y. zeng's user avatar
  • 2,105
2 votes
1 answer
65 views

Applying newcommand/def to subscript whenever one is provided

I have defined a \blue command which I often use with subscripts, e.g. \newcommand{\blue}[1]{{\color{blue} \textup{\textbf{#1}}}} \blue{v}_{\blue{ij}} Question: Is there a way to define \blue in such ...
Louis-Amand's user avatar
7 votes
1 answer
172 views

#1# signature in macro definition

I'm reading the source code of xcolor and I'm a little bit confused about the following definition: \documentclass{article} \usepackage{xcolor} \makeatletter \def\testclr#1#{\@testclr{#1}} \def\@...
Stephen's user avatar
  • 4,484
-1 votes
1 answer
97 views

Ignore Text between \bgroup and \egroup from printing in PDF during runtime [closed]

I would like to exclude the text between \bgroup and \egroup from appearing in the final PDF, i.e. mark it as a comment during runtime. However, the problem here is that the text is not static and \...
FixFox's user avatar
  • 45
0 votes
0 answers
22 views

Access table data to be used for labels on lines plotted in a \foreach loop

I have a large table which contains multiple sets of (x,y) data, and following each such dataset is a constant number, which we can call "C". To save time I want to utilize a \foreach loop ...
Eirik B's user avatar
  • 85
2 votes
1 answer
317 views

Convert Date string format from dd-mm-yyyy to dd.mm.yyyy with some feature

I need to convert a date from one format to another. This is a very simple problem that has already been solved in the topic Latex convert Date string format from mm/dd/yyyyy to dd/MM/yyyy. However, ...
Crosfield's user avatar
  • 119
0 votes
1 answer
113 views

Validity of \def in tikz

The following code does not resolve the defines inside tikzpicture and thus does not print the labels. \documentclass[tikz]{article} \usepackage{keycommand} \usepackage{ifthen} \usepackage{tikz} \...
RootRaven's user avatar
  • 249
0 votes
2 answers
64 views

How to replace single hyphen with other text such as double hyphen?

I want to replace - with --. I am able to replace \\ with -- using the following code: {\def \\ {--\ } #3} but if I try: {\def - {--\ } #3} %Option 1 {\def- {--\ } #3} %Option 2 {\def-{--\ } #3} %...
Omar Shawky's user avatar
3 votes
1 answer
131 views

Define variable in LaTeX with value contain mathematical operator

\documentclass[a4paper,oneside,12pt]{book} \begin{document} \def\s{(1/(2+sqrt(2)))} \s \end{document} I want make a variable \s with the value 1/(2+sqrt(2)). LaTeX cannot automatically ...
Ongky Denny Wijaya's user avatar
2 votes
2 answers
101 views

Tikz Calendar - how to pass argument with '\def'

Given the following code \documentclass[a4paper,20pt]{extarticle} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[czech]{babel} \usepackage[czech]{translator} \usepackage{graphicx, ...
JoudaBouda's user avatar
2 votes
1 answer
88 views

Why is there no `\endgroup`?

I see this code in the book's source "The Not So Short Introduction to LaTeX": \newcommand{\CTANref}{\begingroup \urlstyle{tt}\Url} % \def\CTAN|#1|{\href{http://www.ctan.org/tex-archive/#...
fishfin's user avatar
  • 301
0 votes
0 answers
45 views

How to perform a foreach loop over a \def variable [duplicate]

I want to perform in LaTeX a foreach-loop over a def variable: \def\material{Computer,Internet,Home-Folder} \begin{itemize} \foreach \x in {\material} { \item \x } \end{itemize} I want to get ...
jochen's user avatar
  • 11
3 votes
1 answer
58 views

Parameter text getter

To this snippet \def\arg#1#2{\#1 = #1 and \#2 = #2\par} \arg A B C \end I supposed the output like this one #1 = A and #2 = B C But I get (using PDFTeX) #1 = A and #2 = B C . Why such behavior? I ...
Daniel Bandeira's user avatar
0 votes
1 answer
34 views

How to avoid spacing issue when inserting def value in text?

When I define a variable: \def\company{ACME} And use it: The company \company is... I usually have the trailing space eaten by the command resulting in The company ACMEIs So I do the following: The ...
nowox's user avatar
  • 1,417
1 vote
0 answers
42 views

understanding edef [duplicate]

My command \angles defined with \def will not give the same result. I would like to define this command with expansion at definition time, so using \edef. The MWE shows that \def only compiles, but \...
mathteacher's user avatar
2 votes
1 answer
59 views

How to use edef to defines an item from a l3 sequence?

I would like to defines one element from a list with \edef. I wrote the following MWE, which shows that only \def gives a result. However, as i use the result in many complex ways, \def is not an ...
mathteacher's user avatar
1 vote
0 answers
29 views

Inserting a command in a def causes a bug [duplicate]

When I execute the following command, it works: \makeatletter\CROP@center\makeatother But, when I include this command in a \def, as shown below, it no longer works: \def\...
Colas's user avatar
  • 6,892
0 votes
1 answer
109 views

Is it possible to redefine a macro's parameter?

I would like to redefine a macro parameter. This is what I have tried so far: \def#1{$#1$} But it throws this nasty error that I don't know how to fix. ! Missing control sequence inserted. <...
CATboardBETA's user avatar
0 votes
1 answer
86 views

Use a set command in tikz

To make the plots easier, I define commands using \def which I then use in the figures. I would like to define \def for coordinate but when I compile, I have the error: Use of \focale doesn't match ...
Nicolas's user avatar
  • 1,297
1 vote
2 answers
382 views

"! Undefined control sequence." when I use "\def"

Here is a MWE: \documentclass{extbook} \usepackage{xspace} \usepackage{xstring} \usepackage{ifthen} \newcommand\foo[1]{% \def\tempfoo{#1}% #1% } \newcommand\separation[1]{% [\the\numexpr #1\relax ]%...
Pierre Dufays's user avatar
0 votes
1 answer
396 views

Why \def\xxx makes an error: "! Undefined control sequence" [closed]

Why \def\xxx{#1} can make an error: "! Undefined control sequence" ? It can occured because of the content of #1 ? An issue of expansion?
Pierre Dufays's user avatar
2 votes
1 answer
68 views

(expl3) Expand the result of a function in a definition

If I do that: \ExplSyntaxOn \NewDocumentCommand{\foo}{m} { [ \fp_eval:n { #1 } ] } \ExplSyntaxOff ... \edef\bar{\foo{#1} } \edef\baz{\foo{#1+1} } if the argument #1 is 42, and if I write: \...
Pierre Dufays's user avatar
2 votes
1 answer
283 views

\newcommand vs \def for class development

By reading the contents of the file book.cls (the standard book class for LaTeX), I can see there are many uses of \def and \newcommand. What I don't seem to understand is why one is used in some ...
Diego Sejas's user avatar