Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to replace some text (no commands) which are included in my tex-file with some certain string. This shall happen (if possible) without modifying the actual source file. Therefore, I don't want to use some bash/shell script or text-editor replacing function.

Is there any command/toolbox which does this? I have seen that there is an package called l3regex, unfortunately I don't know how to use the tex commands and I don't even know whether this a suitable package for this.

Sorry for being imprecise. Here an example.

\documentclass{article}  
\theUltraCoolRegExpTool{oldRegexp}{newRegexp}
\begin{document}  

\include{file1.tex}
\include{file2.tex}

This here is very long text which also has some formulas $a_{ij} = b*x^2$.

\end{document}  

And here, I e.g. want to replace using a regular expression a_{ij} by X^{ij}. Or maybe some other text in the included files.

share|improve this question
    
Is conditional compilation an option? By this, I mean, extra lines of document that will or will not be executed depending on the state of a variable. –  Steven B. Segletes Feb 7 at 16:49
1  
Please provide a small example document with an indication of the needed replacements. In particular where is the text? in headings? in verbatim sections? in one specific environment? the details will affect the possible answers. –  David Carlisle Feb 7 at 16:49
    
@DavidCarlisle sorry, I edited the question. –  bonanza Feb 7 at 16:56

1 Answer 1

l3regex can apply a regular expression to a supplied list of tokens but the harder part is to reliably apply any operation to text occurring freely in the document rather than text that is the argument to some command.

It is possible in simple cases but likely to be incompatible with packages used in real documents.

So, despite the fact that you say you don't want a bash script, I offer this bash script, it does not edit (or even save) the modified document, just pipes it into latex.

given

\documentclass{article}  
%\theUltraCoolRegExpTool{oldRegexp}{newRegexp}
\begin{document}  

%\include{file1.tex}
%\include{file2.tex}

This here is very long text which also has some formulas $a_{ij} = b*x^2$.


second para.

\end{document} 

The command line

 sed -e "s/a_{ij}/x^{ij}/g" regex.tex  | pdflatex  --jobname=regex \\relax

Produces

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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