Hello,
I am trying to replace characters inside a math environment with their boldface versions. Unfortunately, these characters occur inside the rest of the text, as well.
My text:
text text text text Gtext G G text ....
\begin{align}
f&=gG \\
G &= tG
\end{align}
text textG text $G$ text.
Every G inside \begin{align} \end{align} and between the dollar signs $G$ shall be replaced with
\mathbf{G}.
The others shall remain untouched.
I appreciate every idea :)
Thank you
BIG EDIT: So far, I have a working Program (Python), thanks to the advice and some other findings in stackoverflow.
But the program replaces f.e \quad to \q"replace"ad. if I want to replace all the "u" s with "replace".
from tempfile import mkstemp
from shutil import move
from os import remove, close
import shutil
def replace(file, outputfile, pattern, subst, boundary1, boundary2):
#Create temp file
fh, abs_path = mkstemp()
newfile="tempfile.tmp"
new_file = open(newfile,'w')
old_file = open(file)
inAlign=False
for line in old_file:
if boundary1 in line:
inAlign = True
if inAlign:
print line
print line.replace(pattern, subst)
new_file.write(line.replace(pattern, subst))
else:
new_file.write(line)
if boundary2 in line:
inAlign = False;
#close temp file
new_file.close()
close(fh)
old_file.close()
shutil.move(newfile,outputfile)
replace("texfile.tex","texfile_copy.tex","G", "\\mathbf{G}", "\\begin{align}", "\\end{align}")
Hopefully I got the formatting right...