So as some of you know, I wrote a little script to make my life easier during the process of writing this novel. The purpose of this script was to facilitate multiple versions of my novel. I have a nasty tendency to rewrite parts of my story and I wanted to be able to keep track. This was the script:
#!/bin/bash
IFS="
"
function findfile {
for word in $filetype; do
case $word in
.tex) find /home/ray/ -name *.tex | sort;;
.odt) find /home/ray/ -name *.odt | sort;;
.doc) find /home/ray/ -name *.doc | sort;;
.html) find /home/ray/ -name *.html | sort;;
esac
done
}
function editfile {
for word in $filetype; do
case $word in
.tex) gedit $response;;
.odt) oowriter $response;;
.doc) oowriter $response;;
.html) oowriter $response;;
esac
done
}
function makerevisions {
if [ -d $directory/Revisions/ ];
then
echo "Revisions directory exists"
mkdir $directory/Revisions/$(date +%F-%R)
cp $response $directory/Revisions/$(date +%F-%R)/
else
echo "Revisions directory does not exist"
mkdir $directory/Revisions/
mkdir $directory/Revisions/$(date +%F-%R)
cp $response $directory/Revisions/$(date +%F-%R)/
fi
}
filetype=$(zenity \
--list \
--title="Select filetype" \
--column="Filetype" \
.tex \
.odt \
.doc \
.html)
if [ "$filetype" == "" ]; then
exit 1
fi
response=$(zenity \
--list \
--title="Select file" \
--column="File" \
$(findfile))
filename=${response##/*/}
directory=${response%/*.***}
if [ "$response" == "" ]; then
exit 1
fi
editfile $*
makerevisions
echo $filetype
echo $response
echo $filename
echo $directory
unset IFS
Anyways, to continue my story, I found out that I was being extraordinarily dumb. In many ways I was simply trying to reinvent the wheel. I forgot that there were many tools out there that did the exact same thing. Basically, what I was trying to do was a primitive version control script. I realized relatively recently (to may shame) that I could use things like git and svn to do the exact same thing, except better. So I took a look at a few different tools and I finally decided upon using git. I chose git because, well simply, it appeared to be the easiest to learn and I could use it offline. Now I have a script that I worked so hard on (a symptom of my amateurish scripting abilities) that's, for all intents and purposes, useless.
As a side note, it should be mentioned that git these 'software revision control' tools work particularly well because I am using LaTeX. I am unsure as to whether or not it would track changes just as well if it were regular doc, odt... etc. files.
Showing posts with label script. Show all posts
Showing posts with label script. Show all posts
Wednesday, February 23, 2011
Wednesday, September 22, 2010
Document conversion tool
So I was looking for a tool to convert between various document formats (ie .tex to .doc, .html, .pdf, .odt or any variation thereof) and I found that it was surprisingly difficult finding a tool to convert to .odt. Converting from pretty much anything to either html or pdf was a breeze, however to other formats was more difficult. To convert from .tex to .html, I chose to use latex2html rather than tex4ht because I found the output to be cleaner. Conversion from .tex to .pdf was quite a bit easier. There were a few options. I could either run latex, dvips, and ps2pdf; or latex and dvipdfm; or just pdflatex. These are the standard options. For some reason, when I used these methods the hyperlink table of contents that I created (via hyperref and \tableofcontents) wouldn't show up. I instead chose to use rubber instead. Rubber is a wrapper for LaTeX and some companion programs. With the '-d' option, I was able to make PDFs out of the .tex files that included they hyperlinked table of contents. I don't really understand why this worked and the other methods didn't but it did. Now was the hard part. Converting the .tex files into .odt or into .doc appeared to be near impossible to do cleanly. The best option I had heard was to convert first into HTML and then load it into Office and then save as the desired formats. I found this to work out extremely well. However, I had intended to automate the whole process of document conversion with a script, so this method was not very good for me especially since neither Microsoft Office nor Openoffice.org had very good command line interfaces. This was when I discovered a program called JODConverter. This is a Java program that utilizes Openoffice to convert from one format to another. While this does mean that I probably could have found a way to use Openoffice directly via command line, who was I to complain when there was a program out there to do it for me =D. In the end I wrote a small BASH script to help me with the conversions.
NOTES:
-written in BASH because I'm using Arch Linux
-uses zenity to provide a GUI but is not really necessary
-while this is tailored to my LaTeX usage it can probably be adapted for anything, although just using JODConverter is probably better if LaTeX is not an issue
#!/bin/bash
cd /home/ray/Documents/Novel/Tex/
response=$(zenity --list --title="Choose File" --column=File \
$(ls --hide=*.pdf --hide=*.odt --hide=*.html --hide=Revisions --hide=Output /home/ray/Documents/Novel/Tex/) )
input=$(zenity --list --title="Choose File Type" --checklist --column=Files --column=Description \
TRUE PDF \
TRUE HTML \
TRUE ODT \
TRUE DOC)
cd /home/ray/Documents/Novel/Tex/
IFS='|' ; for word in $input ; do
case $word in
PDF) rubber -f -s -d /home/ray/Documents/Novel/Tex/$response;;
HTML) latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html;;
ODT)latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
jodconverter /home/ray/Documents/Novel/Tex/${response%.*x}.html /home/ray/Documents/Novel/Tex/${response%.*x}.odt
pkill soffice;;
DOC)latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
jodconverter /home/ray/Documents/Novel/Tex/${response%.*x}.html /home/ray/Documents/Novel/Tex/${response%.*x}.doc
pkill soffice;;
esac
unset IFS
cd /home/ray/Documents/Novel/Tex/
rm $(ls --hide=*.tex --hide=*.sh --hide=*.html --hide=*.odt --hide=*.pdf --hide=*.doc --hide=Output --hide=Revisions)
mkdir Output/$(date +%F-%R)
cp $(ls --hide=*.tex --hide=Revisions --hide=Output) /home/ray/Documents/Novel/Tex/Output/$(date +%F-%R)/
#
#echo "-------------------- EXTRA STEPS --------------------"
#echo "1. Open HTML with OpenOffice.org Writer"
#echo "2. Add first-line indent"
#echo "3. Save file as Master.odt"
#echo "4. Export Master.odt to GoogleDocs"
#echo "-----------------------------------------------------"
#cd ~
done
NOTES:
-written in BASH because I'm using Arch Linux
-uses zenity to provide a GUI but is not really necessary
-while this is tailored to my LaTeX usage it can probably be adapted for anything, although just using JODConverter is probably better if LaTeX is not an issue
#!/bin/bash
cd /home/ray/Documents/Novel/Tex/
response=$(zenity --list --title="Choose File" --column=File \
$(ls --hide=*.pdf --hide=*.odt --hide=*.html --hide=Revisions --hide=Output /home/ray/Documents/Novel/Tex/) )
input=$(zenity --list --title="Choose File Type" --checklist --column=Files --column=Description \
TRUE PDF \
TRUE HTML \
TRUE ODT \
TRUE DOC)
cd /home/ray/Documents/Novel/Tex/
IFS='|' ; for word in $input ; do
case $word in
PDF) rubber -f -s -d /home/ray/Documents/Novel/Tex/$response;;
HTML) latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html;;
ODT)latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
jodconverter /home/ray/Documents/Novel/Tex/${response%.*x}.html /home/ray/Documents/Novel/Tex/${response%.*x}.odt
pkill soffice;;
DOC)latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ $response
sed s_${response%.*x}.html#_#_ <${response%.*x}.html>${response%.*x}.html.new
rm index.html
rm ${response%.*x}.html
mv ${response%.*x}.html.new ${response%.*x}.html
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
jodconverter /home/ray/Documents/Novel/Tex/${response%.*x}.html /home/ray/Documents/Novel/Tex/${response%.*x}.doc
pkill soffice;;
esac
unset IFS
cd /home/ray/Documents/Novel/Tex/
rm $(ls --hide=*.tex --hide=*.sh --hide=*.html --hide=*.odt --hide=*.pdf --hide=*.doc --hide=Output --hide=Revisions)
mkdir Output/$(date +%F-%R)
cp $(ls --hide=*.tex --hide=Revisions --hide=Output) /home/ray/Documents/Novel/Tex/Output/$(date +%F-%R)/
#
#echo "-------------------- EXTRA STEPS --------------------"
#echo "1. Open HTML with OpenOffice.org Writer"
#echo "2. Add first-line indent"
#echo "3. Save file as Master.odt"
#echo "4. Export Master.odt to GoogleDocs"
#echo "-----------------------------------------------------"
#cd ~
done
Monday, July 12, 2010
Update
Hello my non-existent readers. I would just like to give everyone an update. I've changed the layout of the blog a bit. I've added a page where you can access the completed story (well completed so far). I will keep the link to the GoogleDocs version of the story in case you wish to download/edit/distribute the story.
Next section of the novel is forthcoming.
Warning: Techy stuff ahead
If you've read my previous post: A Note on Writing Software, you'll know that I am currently using LaTeX to write my story. There are many tools that I use. The three main programs that I use are pdflatex (makes PDFs), oolatex (makes ODT [OpenDocumentText file]), and latex2html (makes a HTML file). The ease in which I can convert into all of these filetypes is one reason why I use LaTeX. Recently though, I discovered something. For those of you who know, oolatex is a part of Tex4ht, which is itself capable of making an HTML file via the htlatex command. Now I have found that when copy/pasting the html produced by the htlatex command into Blogspot, the paragraphs get all messed up. This is why I turned to latex2html. The only caveat with latex2html is that the Table of Contents hyperlinks do not work (keyed to file). This problem was quickly solved by a few sed commands replacing part of the HTML code that tied the links to the file. Anyways I wrote a little bash script so that I can easily convert my .tex file into .odt, .pdf, and .html all in one go. Here is said script
#!/bin/bash
cd /home/ray/Documents/Novel/Tex/
sed "s_\\\usepackage_%\\\usepackage_"Master.tex.new
sed "s_\\\hypersetup_%\\\hypersetup_"Master.tex
mk4ht oolatex Master.tex
sed "s_%\\\usepackage_\\\usepackage_"Master.tex.new
sed "s_%\\\hypersetup_\\\hypersetup_"Master.tex
pdflatex Master.tex
#htlatex Master.tex
latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ Master.tex
sed 's_Master.html#_#_'Master.html.new
rm index.html
rm Master.html
mv Master.html.new Master.html
rm $(ls --hide=*.tex --hide=*.sh --hide=*.html --hide=*.odt --hide=*.pdf)
cd ~
Now there's probably an easier way to do all of this, and I welcome suggestions, but this is the one I've settled upon for now.
Next section of the novel is forthcoming.
Warning: Techy stuff ahead
If you've read my previous post: A Note on Writing Software, you'll know that I am currently using LaTeX to write my story. There are many tools that I use. The three main programs that I use are pdflatex (makes PDFs), oolatex (makes ODT [OpenDocumentText file]), and latex2html (makes a HTML file). The ease in which I can convert into all of these filetypes is one reason why I use LaTeX. Recently though, I discovered something. For those of you who know, oolatex is a part of Tex4ht, which is itself capable of making an HTML file via the htlatex command. Now I have found that when copy/pasting the html produced by the htlatex command into Blogspot, the paragraphs get all messed up. This is why I turned to latex2html. The only caveat with latex2html is that the Table of Contents hyperlinks do not work (keyed to file). This problem was quickly solved by a few sed commands replacing part of the HTML code that tied the links to the file. Anyways I wrote a little bash script so that I can easily convert my .tex file into .odt, .pdf, and .html all in one go. Here is said script
#!/bin/bash
cd /home/ray/Documents/Novel/Tex/
sed "s_\\\usepackage_%\\\usepackage_"
sed "s_\\\hypersetup_%\\\hypersetup_"
mk4ht oolatex Master.tex
sed "s_%\\\usepackage_\\\usepackage_"
sed "s_%\\\hypersetup_\\\hypersetup_"
pdflatex Master.tex
#htlatex Master.tex
latex2html -split 0 -no_navigation -dir /home/ray/Documents/Novel/Tex/ Master.tex
sed 's_Master.html#_#_'
rm index.html
rm Master.html
mv Master.html.new Master.html
rm $(ls --hide=*.tex --hide=*.sh --hide=*.html --hide=*.odt --hide=*.pdf)
cd ~
Now there's probably an easier way to do all of this, and I welcome suggestions, but this is the one I've settled upon for now.
Subscribe to:
Posts (Atom)