This might be a question better suited for bash, but posting here as well in case someone has come across the same issue...

When I edit documents together with other people, I often colorcode edits from different people, so that we each know what we have edited when we read a new version of the document. I do this with e.g. \newcommand{\supernano}[1]{\textcolor{blue}{#1}}, and then in the text I just put new text into \supernano{}.

Once we've all read and discussed the new version, we remove all the color coding, but so far I been doing it manually, by searching for and deleting each instance of \supernano{ and going through the text to find the corresponding }.

Does anyone know of a more efficient way that this could be done? I'm thinking there must be some bash way of using reg expressions to remove the command instances while keeping the text inside, but I haven't been able to find a similar example.

  • 2
    Can't you just change the definition of the command to do nothing but just literally print its argument instead of coloring it?
    – leandriis
    Jun 20, 2021 at 6:23
  • I would like to clean up the file before I submit it to a journal for publishing
    – SuperNano
    Jun 21, 2021 at 0:11

2 Answers 2


Do not delete \supernano. For the final version, just change the definition of the command to type only plain text:

% \newcommand\supernano[1]{\textcolor{blue}{#1}} %%  draft version
\newcommand\supernano[1]{#1}                     %%  final version

But before reinventing the wheel, look at this example of the package changes.

  • Thanks Fran, that's a good idea, but I would also like the option to remove the instances of \supernano{}, because most of the time journals accept latex files as final submission, and I like to have them as clean as possible when I submit
    – SuperNano
    Jun 21, 2021 at 0:07
  • @SuperNano with pandoc -f latex supernanopaper.tex -t latex -o foo.tex being supernano.tex a file with \newcommand\supernano[1]{#1} bar \supernano{foo} baz the outputfoo.tex will have just bar foo baz. But note that in a complete document could be also side effects like add a large preamble or change \section{foo} to \hypertarget{foo}{\section{foo}\label{foo}}.
    – Fran
    Jun 21, 2021 at 1:29

My first recommendation would be to follow @Fran's advice and run \newcommand\supernano[1]{#1}.

If, however, you want to physically remove all instances of \supernano{ and associated instances of } from the input stream, and if you're willing and able to compile your document with LuaLaTeX, you could insert the following code chunk in the preamble of your document:

\usepackage{luacode} % for '\luaexec' macro, escape Lua's '%' as '\%'
\luaexec{ % Define a couple of Lua funcions:
function StripFirstLast ( s ) % Remove first and last chars from input
   return ( s:sub ( 2 , -2 ) )
function DisableSupernano ( s )
   return ( s:gsub ( '\\supernano\%s-(\%b{})', StripFirstLast ) )
% Assign 'DisableSupernano' to LuaTeX's "process_input_buffer" callback:
\AtBeginDocument{\directlua{luatexbase.add_to_callback (
   "process_input_buffer" , DisableSupernano , "DisableSupernano" )}}
  • Thanks, Mico. I haven't used LuaLaTex before. Will this permanently remove the text from the tex file, or will it only do it in a temp file before compiling?
    – SuperNano
    Jun 21, 2021 at 0:10
  • @SuperNano - Neither. By assigning the Lua function to the process_input_buffer callback, it gets to act like a preprocessor. The input file isn't modified, and there is no temp file.
    – Mico
    Jun 21, 2021 at 3:32

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.