0

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

  • @den2042: do you want to disable the highlighting (see TH's answer) or do you want to change the source, i.e. remove \edit{ and the closing} from it? – Mike Jun 27 '17 at 20:55
  • @Teepeemm, there's a second \edit{such as ... \cite{mycitation2}}. – TH. Jun 27 '17 at 21:02
  • @Mike I would like to change the source, i.e. remove \edit{ and the closing} from it. The reason for that is there maybe many more consecutive overlapping edits. I would like to send the clean text to each collaborator – den2042 Jun 27 '17 at 21:41
  • @den2042: that's a job for regular expressions, which I don't know well enough for this, sorry. – Mike Jun 27 '17 at 21:58
  • If you would have similar question, please check ilkkachu answer at unix.stackexchange.com/questions/373772/… – den2042 Jun 27 '17 at 22:57
1

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.

  • @Teepeemm, maybe I don't understand. What is the "closing bracket" here? – TH. Jun 27 '17 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.