Questions tagged [protected-macro]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
21 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 ...
user avatar
  • 21
0 votes
1 answer
24 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.}}} \...
user avatar
  • 5,285
1 vote
1 answer
77 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 ...
user avatar
  • 1,488
1 vote
2 answers
46 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 ...
user avatar
5 votes
1 answer
176 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 ...
user avatar
1 vote
2 answers
52 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\...
user avatar
  • 6,142
2 votes
2 answers
50 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, ...
user avatar
1 vote
1 answer
74 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 ...
user avatar
0 votes
0 answers
34 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 ...
user avatar
  • 1,899
3 votes
1 answer
126 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 \...
user avatar
3 votes
1 answer
67 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 ...
user avatar
  • 23.5k
9 votes
2 answers
429 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 ...
user avatar
1 vote
0 answers
79 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{...
user avatar
4 votes
2 answers
106 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
2 votes
0 answers
277 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 ...
user avatar
6 votes
3 answers
398 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 ...
user avatar
4 votes
3 answers
187 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 ...
user avatar
7 votes
1 answer
92 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 ...
user avatar
  • 22.8k
2 votes
1 answer
90 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{...
user avatar
  • 3,210
0 votes
1 answer
172 views

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

In this script: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\myfigure}[1]{% ...
user avatar
  • 6,873
10 votes
2 answers
503 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 ...
user avatar
  • 125
2 votes
1 answer
283 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} \...
user avatar
  • 1,193
1 vote
1 answer
292 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, ...
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{\...
user avatar
  • 411
3 votes
0 answers
174 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 ...
user avatar
2 votes
1 answer
311 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. ...
user avatar
  • 377
2 votes
1 answer
95 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}} ...
user avatar
2 votes
0 answers
212 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} \...
user avatar
9 votes
1 answer
1k 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 ...
user avatar
  • 8,734
5 votes
1 answer
696 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 ...
user avatar
  • 153
1 vote
1 answer
390 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 ...
user avatar
  • 10.7k