<3 LaTeX <3

A fair portion of my supposedly study-oriented weekend was spent in the recovery of ebooks deleted in an iOS update gone wrong, and the ongoing hunt for a worthy ePub reader for my iPad.

Besides my iPad, I have spent most of today (Sunday) in the company of an old friend, that most excellent of typesetting solutions, LaTeX. Microsoft Word is a fantastic tool for quick documents, but its very nature as a WYSIWYG editor makes it leaves much to be desired as a tool for quality typeset documents. There is no separation of style and content (like HTML and CSS for instance).

Because of this unholy marriage of elements, I can spend as much time in the play of dials and sliders as I do writing. LaTeX strictly separates content and style-I define spaces, typefaces, indentations, fonts, and other styles at the start of the document, and then as I write I simply insert the tags as ncesessary. Example “hello world” .tex file:

\documentclass{article}
\title{Cartesian closed categories and the price of eggs}
\author{Jane Doe}
\date{September 1994}
\begin{document}
\maketitle
Hello world!
\end{document}


prep

For reasons-reasons other than convenience-that I would not be able to fully articulate should you choose to put a gun to my head, I store my website’s files (WordPress), database and content images separately. I guess if one’s data centre is bombed then the other two will be okay?

Well, back to the convenience. I post a great many images to this blog; for the aforementioned convenience, I store my images in Dropbox. I can quickly and easily move, rename or alter images on my blog without having to piss about with FTP. Now, beyond handling the core image processing I don’t want to get bogged down in resizing, foldering, renaming and uploading all of those files. Because of this I script the action, but my current script only creates preview and thumbnail sizes:

 #!/bin/sh

 MED=m SML=s mkdir -p $MED$SML for file in $(find . -iname "*.jpg") do cp$file $MED cp$file $SML done mogrify -quality 90 -resize 540x540+0+0$MED/*.jpg mogrify -quality 90 -gravity center -crop 256x256+0+0 $SML/*.jpg  exit 0  Today I want to add three two new features to it: 1. Move the given folder into my ~/Dropbox/public/content folder. 2. Construct the URL code I use and ready it for pasting. Typical code is below: <a title="Click to view larger size" href="http://dl.dropbox.com/u/4144919/content/1466601748/1.jpg"><img src="http://dl.dropbox.com/u/4144919/content/1466601748/1.jpg" alt="" /></a>  For both steps, I need the ability to output only the name of the current directory I am working in, since this directory will be named according the number to the post. In the case of this blog post the folder name will be 1466601748. I spent about three hours fucking about with awk, sed, Google and pipes before I discovered a very simple one-liner that delivers the folder name unto me:  basename$(pwd)

 

[mark][1466601748] # pwd /home/mark/1466601748 [mark][1466601748] # basename $(pwd) 1466601748  Call me stupid. So, #1 is the easiest to achieve:  [mark][1466601748] # mv$(pwd) ~/Dropbox/Public/content 

#2, generating the URL code, will be interesting, although trivial too. It seems like the easiest way is to echo the URL while I insert the post number and then stick the hot, steaming result into my clipboard. This works fine…but my sense of neatness is screaming at me that there is probably a more elegant way to achieve my goal:

 #!/bin/sh

 USERID=4144919 POSTID=$(basename$(pwd)) echo \<a title=\"Click to view larger size\" href=\"http\:\/\/dl.dropbox.com\/u\/$USERID\/content\/$POSTID\/1.jpg\"\>\<img src=\"http\:\/\/dl.dropbox.com\/u\/$USERID\/content\/$POSTID\/m\/1.jpg\" alt=\"\" \/\>\<\/a\> | xclip -sel clip 

exit 0 

Short version: Escape the shit out of everything and let God judge the survivors. Using $USERID instead of a hard-set user number gives me a little bit of portability for you, the consumer. #!/bin/sh PUB=/home/mark/Dropbox/Public/content/ MED=m SML=s USERID=4144919 POSTID=$(basename $(pwd)) mkdir -p$MED $SML for file in$(find . -iname "*.jpg")
do
cp $file$MED
cp $file$SML
done

mogrify -quality 90 -resize 540x540+0+0 $MED/*.jpg mogrify -quality 90 -gravity center -crop 256x256+0+0$SML/*.jpg

echo <a title=\"Click to view larger size\" href=\"http://dl.dropbox.com/u/$USERID/content/$POSTID/1.jpg\"><img src=\"http://dl.dropbox.com/u/$USERID/content/$POSTID/m/1.jpg\" alt=\"\" /></a> | xclip -sel clip

mv $(pwd)$PUB

exit 0


Enjoy.

/smrt