Skip to main content

Questions tagged [protected-macro]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

Try-Except on performing an expansion

Is it possible to write a function that essentially does: function \tryexpand (\foo): try: expand(\foo) except (Argument of \@following has an extra }): store "\relax&...
Hyperplane's user avatar
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
1 answer
61 views

Functions with Expansion Protection when working with Section Headings

I would like to understand why defining new section heading would require function to have protection from expansion.
Veak's user avatar
  • 1
2 votes
1 answer
145 views

Protected Restriction

Have seen \cs_new_protected:Nn \feuds_newteorema_define:nn Is this just a definition of a function named \feuds_newteorema_define (taking two arguments as far as I can tell), Or is it something else ?...
Veak's user avatar
  • 1
0 votes
1 answer
42 views

Aligning `\marginpar` with section title

I tried to use a custom defined command, which uses \marginpar, inside \section. According to another SE post, I have to \protect it. But after some trial and error in my custom package, it breaks if ...
Gargantuar's user avatar
  • 1,241
0 votes
0 answers
26 views

\graphicspath{{⟨cmd⟩/}}: graphic files found if ⟨cmd⟩ defined with \newcommand but not found with \DeclareDocumentCommand

Suppose a graphic file myimage contained in a subdirectory images of the current directory. With the following MCE: \documentclass{article} \usepackage{graphicx} \newcommand{\ImagesDirectory}{images} ...
Denis Bitouzé's user avatar
3 votes
2 answers
306 views

Why don't c- and f-type expansions respect protected commands?

According to this answer, all functions without a star are (or at least should be) \protected, this way they don't expand on x or e type expansion or when written to a file. f and c type expansion ...
Evan Aad's user avatar
  • 11.1k
2 votes
1 answer
400 views

Reasons for not using \protect

So I have been looking into the details of what it means for a macro to be \protected and thus be made robust. I have found this question where an answer explains the concept of what it means for a ...
Raven's user avatar
  • 3,043
1 vote
1 answer
247 views

Protection setting \@currentlabelname to give a "name" to a \phantomsection

This is a follow-up question to nameref With Arbitrary Text and also Refer to arbitrary text (without numbering and not by section) To summarize, the question was about how to reference to an ...
xmarteo's user avatar
  • 21
0 votes
1 answer
33 views

How to Center All of the Lines of Long Text Insertions in the TOC

Consider the code which has no problem centering short text insertions in the TOC: \documentclass{book} \begin{document} \tableofcontents \addtocontents{toc}{\hfil\protect {\Large{\textbf{PART I.}}} \...
DDS's user avatar
  • 9,768
1 vote
1 answer
151 views

Using custom units with siunitx v3 in captions - is \protect insufficient?

I am using my previously discussed custom commands (also provided below), in siunitx. Since version 3, I am no longer able to use them in captions, whereas previously, adding \protect before them ...
Coby Viner's user avatar
  • 1,949
1 vote
2 answers
233 views

How does \protected deal with arguments? Is it different than \protect?

According to this answer \protect\foo expands to something like \noexpand\protect\noexpand\foo when it gets saved to a macro (e.g. in a context like a beamer frame). I think \protected\def basically ...
Peter Gerdes's user avatar
5 votes
1 answer
285 views

How can this complex command be broken down and explained for someone starting with Tex?

I got this Tex command, as a solution to a different problem and it works. But I have trouble understanding the details of how it works since I'm not that proficient in Latex coding and I want to ...
Sharky Bamboozle's user avatar
1 vote
2 answers
57 views

How to automatically protect all the commands passed in an argument?

I need to write to an auxfile some mathematical formulas. The following MWE does not work: \documentclass{article} \usepackage{amsmath} \newwrite\filehandle \newcommand{\addToFile}[1]{\immediate\write\...
Colas's user avatar
  • 6,892
2 votes
2 answers
64 views

How do you protect fragile commands or commands in general inside \bib* fields of amsrefs?

I would like to kindly inquire how to protect commands (which I would normally presume to be fragile) in the non-citable \bib* bibliographic fields of the package amsrefs. Consider the following MWE1, ...
beethovengg14's user avatar
1 vote
1 answer
212 views

how to use newlabel in journal style file with hyperref

I am using the bio.cls style file from OUP. However, there is a conflict which happens when i use hyperref. I use: \usepackage[colorlinks=true]{hyperref} and the compilation gives the following ...
user3236841's user avatar
0 votes
0 answers
36 views

newcommand to apply mintinline for C++ breaks on include statements [duplicate]

Staying away from LaTeX for barely more than 2 years has devastating effects. I think once I knew how to protect this stuff, but I have no idea now. I defined the newcommand below to be faster in ...
Enlico's user avatar
  • 2,612
3 votes
1 answer
173 views

eplain packages with plain tex no longer have all needed definitions

If one uses tex rather than pdftex, one gets errors when inputting certain packages with eplain. For example, let test.tex be this file: \input /usr/share/texlive/texmf-dist/tex/eplain/eplain \...
Russ Lyons's user avatar
3 votes
1 answer
94 views

Thoughts about taking LaTeX's \protect-mechanism into account?

In this question I am not asking for code. I'm asking before I start implementing: Which direction do you think makes the most sense? I am about to define a fully expandable macro to be used with ...
Ulrich Diez's user avatar
  • 29.7k
9 votes
2 answers
793 views

What is the fifth possible value of \protect?

Section "11.4 Robust Commands and \protect" of source2e.pdf (File d: ltdefns.dtx Date: 2020/02/27 Version v1.5g) says that \protect can have one of five possible "values" but lists ...
Jewdokija's user avatar
1 vote
0 answers
117 views

Beamer Custom ToC not working as expected

I hacked a table of frames for beamer and got a weird situation I do not understand. \documentclass{beamer} \makeatletter \newcommand\listofframes{\@starttoc{lbf}} \makeatother \setbeamertemplate{...
Nobody-Knows-I-am-a-Dog's user avatar
4 votes
2 answers
260 views

A symbol table with protection issues

I wanted to create a table of symbols that is easy to read in LaTeX, so something like: \begin{tabular}{*4M} < & \le & \ll & \lll \\ > & \ge & \...
user avatar
3 votes
0 answers
681 views

Why is \DeclareRobustCommand[*] still used by LaTeX?

As LaTeX requires eTeX now it would be much easier to replace all the definitions of robust commands with \DeclareRobustCommand[*]... by \protected[\long]\def..., wouldn't it? Which advatages come ...
Weißer Kater's user avatar
6 votes
3 answers
575 views

Questions about `\cs_new:...` and friends and their TeX relatives regarding global, local, long, nopar, protected, expandable and naming

This question is two-fold. Unfortunately, one side is opinionated, i.e. something to close-vote, so I put that part at the end and hope no one notices... The other side (coming first) are serious ...
Robert Siemer's user avatar
4 votes
3 answers
262 views

\input{} inside \chemfig{}

I'm likely ignoring something fundamental here and was hoping for some hints. Please see the inset mwe. Towards having a library of chemfig symbols, I see value in being able to point to a ...
John Chris's user avatar
7 votes
1 answer
102 views

Use of \noexpand in the implementation of \TextOrMath for eTeX

In latexrelease 2015/01/01, there are two implementations of \TextOrMath: one for regular TeX, the other one for eTeX-like engines (more precisely: those which support \protected). My question ...
frougon's user avatar
  • 24.4k
2 votes
1 answer
132 views

How to change zero to dotted zero in an enumitem label?

MWE \documentclass[a4paper,11pt]{book} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage{enumitem} \makeatletter \protected\def\pmzerodot{% \nfss@text{% \sbox0{...
Özgür's user avatar
  • 3,344
0 votes
1 answer
196 views

Protect fragile variable in file path. Case of \ifthenelse in \includegraphics{}

In this script: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\myfigure}[1]{% ...
Viesturs's user avatar
  • 8,095
10 votes
2 answers
631 views

What is the difference between \unexpanded and \protected in ConTeXt?

EDIT: It turns out that \unexpanded in ConTeXt is different from \unexpanded in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly. From the ε-TeX manual: Protected ...
G.S.'s user avatar
  • 125
2 votes
1 answer
324 views

authblk with protected commands and pdflatex

When trying to use this answer to add a linked image to an author with the authblk package, somehow all the following text is shifted, with pdfLaTeX: \documentclass{scrartcl} \usepackage{scalerel} \...
quazgar's user avatar
  • 1,273
1 vote
1 answer
443 views

passing a parameter to nested macro inside caption

I'm having a really hard time understanding this error in a massive document. I took the time to work out a "minimal example", so I could post the error with precision. Please, when trying to answer, ...
DrBeco's user avatar
  • 237
0 votes
0 answers
11 views

Extra White Space after iftenelse in Title [duplicate]

To begin, here is a MWE: \documentclass[12pt]{article} \usepackage{float} \usepackage{tikz} \usepackage{subfig} \usepackage{ifthen} \begin{document} \newcommand{\titlename}[1] { \ifthenelse{\...
bill999's user avatar
  • 463
3 votes
0 answers
207 views

Automatically `\protect` arguments sent to existing command

Say you are using titlecaps and you have the following code: \documentclass{article} \usepackage{titlecaps} \begin{document} \def\makemytitle#1{{\Large \titlecap{#1}}} \makemytitle{The lazy fox ...
Andreas Storvik Strauman's user avatar
3 votes
1 answer
521 views

\protect vs \texorpdfstring in description lists' keys

I'm referring to chapters and sections in a description list. I want the link to include the chapter or section part as well. I found two options to achieve this: use \protect or use \texorpdfstring. ...
Daniel's user avatar
  • 429
2 votes
1 answer
100 views

New command within glossaries ›first‹ needs to be protected?

Consider following MWE \documentclass{scrartcl} \usepackage{xspace} \makeatletter \newcommand\BC{\,v.\,Chr\@ifnextchar.{}{.\relax\@\xspace}} \newcommand\AD{\,n.\,Chr\@ifnextchar.{}{.\relax\@\xspace}} ...
lukascbossert's user avatar
2 votes
0 answers
253 views

Write fully expanded macros to auxiliary files

Considering the following code snippet: \documentclass{article} \usepackage{xparse} % \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \NewDocumentCommand{\edeftest}{m}{\edef\test{#1}#1} \...
Emilio Lazo's user avatar
9 votes
1 answer
2k views

Moving arguments and \protect: coming to grips with the definitions

I'm trying to understand the precise semantics of \protect as described in the beginning of section 11.4 Robust commands and protect of the source2e document, the annotated source code of the LaTeX2e ...
Evan Aad's user avatar
  • 11.1k
5 votes
1 answer
866 views

How to unprotect a command to expand it?

This is another question about protection and expansion, that I still don't understand well… (and I guess this is my problem here). I read especially How do I "unprotect" an argument?, and ...
user73438's user avatar
  • 153
1 vote
1 answer
987 views

Correct way to compare macro definitions that contain protected macros, e.g., bibnamedelima

I'm trying to compare the content of \partnamefamily of an author's name in biblatex against a manual definition that is stored in another macro, lets call it \family, using \ifdefequal. So, I have ...
adn's user avatar
  • 11.4k