I am trying to combine the answers of Remove extra curly braces and \def'ed plain-text argument behaves differently from plain text, and I am failing. Here's an MWE:
\documentclass{article}
\makeatletter
\usepackage{seqsplit}
\newcommand{\dosomething}[1]{\expandafter\seqsplit\expandafter{\@firstofone#1}}
\begin{document}
\def\kong{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}
\def\kongg{\kong}
\def\konggg{{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}}
% works
\dosomething{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}
% works, too
\expandafter\dosomething{\expandafter\kong}
% works with extra {...}
\dosomething{{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}}
% works with extra {...}, too
\expandafter\expandafter\expandafter\dosomething{\expandafter\expandafter\expandafter\kongg}
% does not work
\expandafter\expandafter\expandafter\dosomething{\expandafter\expandafter\expandafter\konggg}
\end{document}
For the larger picture, this is what I am getting at:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,hyperref}
%1 \usepackage{cleveref}
\usepackage{showlabels,xpatch,seqsplit}
\makeatletter
\patchcmd{\SL@margintext}{\{\SL@prlabelname{#1}\}}{#1}{}{err}
\patchcmd{\maketag@@@}{{\df@label}}{{\expandafter\df@label}}{}{err}
\patchcmd{\showlabelsetlabel}{#1}{\raisebox{0pt}[0pt][0pt]{\parbox{1.5\marginparwidth}{\scriptsize\vspace*{-0.5\baselineskip}\seqsplit{#1}}}}{}{err}
%2 \renewcommand{\showlabelsetlabel}[1]{\meaning\df@label}
%4 \newcommand{\dosomethingelse}[1]{\expandafter\seqsplit\expandafter{\@firstofone#1}}
%4 \patchcmd{\showlabelsetlabel}{\seqsplit}{\dosomethingelse}{}{err}
\begin{document}
%3 \patchcmd{\label@in@display@noarg}{{{#1}}}{{#1}}{}{err}
\section{A}
\label{sec:Loooooooooooooooooooooooooooooooooooooooooong}
\begin{equation}
\label{eqn:Loooooooooooooooooooooooooooooooooooooooooong}
X = Y
\end{equation}
\end{document}
This code behaves well until I load cleveref
(uncomment %1
). You will see why after uncommenting %2
: \df@label
, set by amsmath
's \label@in@display
, has an extra layer of {...}
.
cleveref
, on the other hand, seems to be the one introducing this:
\def\label@in@display@noarg#1{\cref@old@label@in@display{{#1}}}%
\def\label@in@display@optarg[#1]#2{%
\cref@old@label@in@display{[#1]{#2}}}%
And it seems to depend on it, as you can see when you try to xpatch
it out (uncomment %3
). So instead of that, I tried to remove the curly braces as before (comment %2
, uncomment %4
), to no avail.
\label
works usually -- there must be interferences ;-)