Replacing all instances of one set of words with another word

3,824

Solution 1

In Texmaker, you can use Replace All. You use hot key Ctrl + R. enter image description here

Solution 2

If you're willing and able to use LuaLaTeX, one could write a Lua function that performs the string replacement job "on the fly".

That said, I'd say it must be easier to do this replacement once and for all in one's text editor.

% !TeX program = lualatex
\documentclass{article}
\usepackage{luacode}
\begin{luacode}
   function bezier ( s ) 
      return ( string.gsub ( s , "[Bb]ezier", "B\\'ezier" ) )   
   end
\end{luacode}
\AtBeginDocument{\directlua{luatexbase.add_to_callback( 
   "process_input_buffer", bezier, "bezier" )}}

\begin{document}
aaa bezier bbb Bezier ccc
\end{document}
Share:
3,824

Related videos on Youtube

Sam Harper
Author by

Sam Harper

Updated on December 29, 2020

Comments

  • Sam Harper
    Sam Harper almost 3 years

    I wish to replace all instances of Bezier and bezier with B\'{e}zier in my LaTeX document. It's in a masters thesis of 30 pages.

    Two questions. How could one achieve the above with a new command or similar approach? And, is it going to be worth the amount of time i save or will it likely cause some issues further down the line?

    • Au101
      Au101 almost 7 years
      Surely it's much much easier to do this with the editor. Simple find and replace
    • Sam Harper
      Sam Harper almost 7 years
      i would agree @Au101 but i have probably used the following about 150 times throughout the paper, so just tying to find a time effiecient possibility
    • jon
      jon almost 7 years
      Repetitive tasks are better left to a computer than a human, but that doesn't mean TeX is always the way to do it. In this case, things like sed or awk (or etc.) are the better choice. (And, off-topic, but, in 2016, use UTF-8 and input an é directly rather than \'{e}.)