# Replace string in .tex file then compiled by latex

The document is created from different file and included using \input{filename.tex}. In all these file I want to replace a string by a new string but not losing grammar and pulling checking provide by the editor.

For example replace latex or Latex by Custom-\LaTeX{}.

a preferable solution is not to defined an addition commend in which the text must to be replace. I am looking form similar to C/C++ #define directive.

## Update using chickenize

When using

\addtosubstitutions{latex}{Latex}
\substitutewords


the .bbl could not be generated by biblatex

When using

\addtosubstitutions{latex}{Latex\ae}
\substitutewords


the error was

(/usr/share/texlive/texmf-dist/tex/luatex/chickenize/chickenize.tex)) [\directlu
a]:1: invalid escape sequence near '\T'.


• the entire TeX language is a macro processing language not dissimilar to the C macro pre-processor, so in latex you would normally have input \foo which you can define using \def or \newcommand similar to #define, but you are suggesting input being latex rather than a macro. You did not mention luatex in the question but you tagged the question luatex, if that is a possibility you can use the input buffer callback to make arbitrary lua pattern string replacements o the input (see the chikenize package for some good examples) – David Carlisle Sep 30 '18 at 13:29
• you can replace some string with function replace in your editor. some editor enable to do this in all open files in editor. – Zarko Sep 30 '18 at 13:44
• @ David: both \def and \newcommand require the string to start with '\'. Do you have link to chikenize package I can't find it. – Johan Sep 30 '18 at 14:56
• @ Zarko: the editors replace function will also replace the text that the spelling/grammar checker see. – Johan Sep 30 '18 at 14:57
• while you can use lua here it isn't at all clear why you do not want to use tex macros which are by far the most natural mechanism to use in TeX? What is so bad about starting with \  hard to use tex and avoid \  – David Carlisle Oct 1 '18 at 20:14

The \addtosubstitutions macro is not escaping strings correctly. You could either fix it in the call to \addtosubstitutions using

\addtosubstitutions{latex}{\luaescapestring{Latex\ae}}


or you could override the definition

\def\addtosubstitutions#1#2{
}


MWE:

\documentclass{article}

\usepackage{chickenize}