Remove backslash from string

\documentclass{article}
\newcommand{\removeabs}[1]{%
  %{\catcode92=9 \endlinechar-1 \scantokens\expandafter{\detokenize{#1}}}%
  {\catcode92=9 \endlinechar-1 \scantokens{#1}}%
}
\begin{document}
\removeabs{\the slash is removed here}
\removeabs{and also \here}+++
\end{document}

But your use case is not really known...

enter image description here

As pointed out by @A.Ellett there is no real need for \detokenize.

\documentclass{article}
\newcommand{\removeabs}[1]{%
  {\catcode92=9 \endlinechar-1 \scantokens{#1}}%
}
\begin{document}
\removeabs{\the slash $E=mc^2$ is removed here}
\removeabs{and also \here}+++
\end{document}

enter image description here

Perhaps you want to store in macro, the following shows how to do it (but the \x here is used and discarded).

Notice though that therein you should not be some active character with a definition not compatible with an \edef. The ~ and the UTF-8 things are OK.

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\removeabs}[1]{%
  {\catcode92=9 \endlinechar-1 \everyeof{\noexpand}\edef\x{\scantokens{#1}}\x}%
}
\begin{document}
\removeabs{\the slash $E=mc^2$ is~~~~removed here}
\removeabs{and also éééé \here}+++
\end{document}

enter image description here

Thanks to @A.Ellett!


With expl3:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\removebs}{m}
 {
  \tl_set:Nn \l_tmpa_tl { #1 }
  \regex_replace_all:nnN { \cC. } { \c{cs_to_str:N} \0 } \l_tmpa_tl
  \tl_use:N \l_tmpa_tl
 }

\ExplSyntaxOff

\begin{document}

\removebs{\the slash is removed here}

\removebs{\the\ slashes are removed here}

\removebs{and also \here}

\end{document}

Note that the space after \the in the first case doesn't disappear, because it was ignored to begin with.

enter image description here

Tags:

Macros