Fixing latex tags

Thought this might be handy if we ever want to do any batch editing of wiki pages.

#!/bin/bash                                                                                                                                                                                                                                                                    
for i in `trac-admin ./ wiki list | tail -n +4 | head -n -1 | awk -F ' ' '{print $1}'`
do
        trac-admin ./ wiki export $i | perl -pe 's/\[\[latex\(([^\$])(.*?)\)]]/\[\[latex\(\$$1$2\$\)]]/g' | trac-admin ./ wiki import $i
done

It basically selects all of the wiki pages and then parses them through a perl regex parser that replaces

[[latex($<some stuff>$)]]

with

[[latex($<some stuff>$)]]

but leaves

[[latex($<some_otherstuff>$)]]

alone. This should fix most things - though it may miss things like

[[latex($ $a=b$$)]]

And here is a script for batch-editing blog posts. Since the blog posts are managed through a plugin they have their own table - and trac-admin does not provide any easy front end… So you should only modify the trac database after shutting down the web server.

#!/bin/bash                                                                                                                                                                                                                                                                    
#make sure to shut down wiki server                                                                                                                                                                                                                                            
sqlite3 db/trac.db << EOF                                                                                                                                                                                                                                                      
.out fullblog_dump                                                                                                                                                                                                                                                             
.dump fullblog_posts                                                                                                                                                                                                                                                           
.exit                                                                                                                                                                                                                                                                          
EOF                                                                                                                                                                                                                                                                            
perl -p -i -e 's/\[\[latex\(([^\$])(.*?)\)]]/\[\[latex\(\$$1$2\$\)]]/g' fullblog_dump
sqlite3 db/trac.db << EOF                                                                                                                                                                                                                                                      
DROP TABLE fullblog_posts;                                                                                                                                                                                                                                                     
.read fullblog_dump                                                                                                                                                                                                                                                            
.exit                                                                                                                                                                                                                                                                          
EOF  

This will unfortunately modify this blog post as well :|

Comments

No comments.