[Tex/LaTex] Remove a specific latex command from the text AND closing bracket behind it

text manipulation

How to remove a specific latex command from the text AND closing bracket behind it, but to keep the text inside the brackets/

senseless example:

We \edit{Introduce a} model for analyzing \emph{data} from various
experimental designs, \edit{such as paired or \url{http://www/}
longitudinal; as was done 1984 by NN \cite{mycitation} and by NNN
\cite{mycitation2}}.

Output:

We Introduce a model for analyzing \emph{data} from various
experimental designs, such as paired or \url{http://www/}
longitudinal; as was done 1984 by NN \cite{mycitation} and by NNN
\cite{mycitation2}.

PS. I am introducing a lot of small edits into my tex file. I want those edits to be highlighted, so my collaborator can see them. But afterwards I would like to remove all highlights and to send the text to a reviewer.

The question was originally asked at https://unix.stackexchange.com/questions/373662/awk-sed-remove-a-specific-latex-command-from-the-text-and-closing-bracket-behind. But example there was too soft

Best Answer

New answer

Since it sounds like you want to modify your source code, I've written a new nonanswer.

This is not something that you want to be doing from within TeX. You might be tempted to try to write a regular expression for it, but you're not going to succeed using real regular expressions.

A better solution might be to instruct your editor to do what you want. For example, in Vim, with the cursor over the \ in \edit{...}, entering 5xma%x`ax deletes the first 5 characters (the \edit), marks the current location (the {), moves to the matching }, deletes it, moves back to the marked location and deletes it. Combined with /\\edit{ as part of a VIM macro makes deleting them pretty easy.

Credit to Justin Smith's answer for the ma%x`ax. (Or as the edit notes, %x``x has the same effect as ma%x`ax.)

Old answer

This answer assumed you wanted to simply make \edit not do anything which it's now clear is not what you want.

You want to (re)define \edit to just output its argument without change.

\renewcommand\edit[1]{#1}

Here's an example.

\documentclass{article}
\usepackage{xcolor}
\usepackage{url}

\newcommand\edit[1]{\textcolor{blue}{#1}}

%\renewcommand\edit[1]{#1}

\begin{document}
We \edit{Introduce a} model for analyzing \emph{data} from various
experimental designs, \edit{such as paired or \url{http://www/}
longitudinal; as was done 1984 by NN \cite{mycitation} and by NNN
\cite{mycitation2}}.

We Introduce a model for analyzing \emph{data} from various
experimental designs, such as paired or \url{http://www/}
longitudinal; as was done 1984 by NN \cite{mycitation} and by NNN
\cite{mycitation2}.
\end{document}

enter image description here

If I uncomment the \renewcommand line, I get the following.

enter image description here

In this case, the two paragraphs are identical.