<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non-random ramble &#187; latex</title>
	<atom:link href="http://jimbarritt.com/non-random/category/code/latex/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Make Latex bundle for TextMate output files to a &#8216;target&#8217; directory.</title>
		<link>http://jimbarritt.com/non-random/2009/06/15/make-latex-bundle-for-textmate-output-files-to-a-target-directory/</link>
		<comments>http://jimbarritt.com/non-random/2009/06/15/make-latex-bundle-for-textmate-output-files-to-a-target-directory/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 10:46:58 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2009/06/15/make-latex-bundle-for-textmate-output-files-to-a-target-directory/</guid>
		<description><![CDATA[I&#8217;m using the LaTeX bundle in TextMate to write pdf files. Its cool, and gives a nice report of whats going on. However, it has the habit of putting all the generated files into the same directory as your source, TEX file. I would like it to put everything in a sub directory called &#8220;target&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using the LaTeX bundle in TextMate to write pdf files. </p>
<p>Its cool, and gives a nice report of whats going on. </p>
<p>However, it has the habit of putting all the generated files into the same directory as your source, TEX file. I would like it to put everything in a sub directory called &#8220;target&#8221; so I can easily keep these seperate. </p>
<p>Its easy to get the pdflatex command to do this, you simply specify the <code>-output-dir=./target</code> on the options. And happily, the LaTeX bundle allows me to pass custom options. </p>
<p>1) After running <code>CMD-R</code>, there is a button for &#8220;preferences&#8221; at the bottom of the output window. Click this and in the typesetting box, select pdflatex and then you can put some options. Put in the string above. </p>
<p>Sweet, so now it generates its stuff into the target dir. Except for a file called (synctex.gzip).</p>
<p>However, the viewer (<a href="http://skim-app.sourceforge.net/">Skim</a> is good as it syncs the doc position),  is still looking for the pdf in the source folder .</p>
<p>A bit of delving about can hack this to work.</p>
<p>2) Open the texMate.py file. This can be found by showing package contents for your TextMate.app, and going into <code>Contents/SharedSupport/Bundles/Latex.tmbundle</code></p>
<p>This itself is a package, so again show package contents. <code>Support/bin</code> is where the texMate.py file is.</p>
<p>You are looking for a function called <code>run_viewer</code> in my version its on line 182. change the following line:</p>
<pre name="code" class="python">
fileNoSuffix = getFileNameWithoutExtension(fileName)
</pre>
<p>to</p>
<pre name="code" class="python">
fileNoSuffix = 'target/' + getFileNameWithoutExtension(fileName)
</pre>
<p>Ok so now it should open up ok, but you also want to be able to jump to a point from the tex file. Do this in <code>sync_viewer</code>, in mine its just above, on line 172.  the line you need to change is the same.</p>
<p>This opens the viewer ok, but doesnt sync. Here is where our <code>synctex</code> file comes in. Remember its up in the source folder?</p>
<p>What we need to do is MOVE it to the target folder once the build is completed.</p>
<p>3) Write a new function to move the synctex file to the target dir:</p>
<pre name="code" class="python">
def move_synctex_file_to_target(fileName, filePath):
    """Copies the synctex file to the target directory"""
    fileNoSuffix = getFileNameWithoutExtension(fileName)
    sourceFilename = fileNoSuffix + '.synctex.gz'
    syncfile = shell_quote(filePath + '/' + sourceFilename)
    targetPath = shell_quote(filePath + '/target/')
    mvCommand = 'mv '+ syncfile + ' ' + targetPath
    print '&lt;p class="info"&gt;Moving synctex file to target [%s]...&lt;/p&gt;' % (mvCommand)
    runObj = Popen(mvCommand,shell=True,stdout=PIPE,stdin=PIPE,stderr=STDOUT,close_fds=True)
    stat = runObj.wait()
    return stat
</pre>
<p>Then you can insert this into the part which is doing the build:</p>
<pre name="code" class="python">
   elif texCommand =='latex':
        texCommand = engine + " " + constructEngineOptions(tsDirs,tmPrefs)
        texStatus,isFatal,numErrs,numWarns = run_latex(texCommand,fileName,verbose)
        if engine == 'latex':
            psFile = fileNoSuffix+'.ps'
            os.system('dvips ' + fileNoSuffix+'.dvi' + ' -o ' + psFile)
            os.system('ps2pdf ' + psFile)
        move_synctex_file_to_target(fileName, filePath)
        if tmPrefs['latexAutoView'] and numErrs < 1:
            stat = run_viewer(viewer,fileName,filePath,tmPrefs['latexKeepLogWin'],'pdfsync' in ltxPackages or synctex)		
</pre>
<p>We already have these two variables, fileName and filePath. This was line 603 in my installation.</p>
<p>QUESTION: is all this worth it ?</p>
<p>Not sure. Also haven't tried bibtex yet.</p>
<p>So bibtex just required me to change it so that when you loop over the aux files you invoke bibtex with "./target" i.e.:</p>
<pre name="code" class="python">
        runObj = Popen('bibtex'+" "+shell_quote("./target/" +bib),shell=True,stdout=PIPE,stdin=PIPE,stderr=STDOUT,close_fds=True)
</pre>
<p>Then you have to run bibtex and run pdflatex twice to update your references.</p>
<p>The whole thing is uploaded <a href="http://jimbarritt.com/non-random/wp-content/uploads/2009/06/texmatepy.txt">here - texMate.py.txt</a> so in theory you can just swap yours out.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F06%2F15%2Fmake-latex-bundle-for-textmate-output-files-to-a-target-directory%2F&amp;title=Make%20Latex%20bundle%20for%20TextMate%20output%20files%20to%20a%20%E2%80%98target%E2%80%99%20directory." id="wpa2a_2"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/06/15/make-latex-bundle-for-textmate-output-files-to-a-target-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sweet Search And Highlight Command</title>
		<link>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</link>
		<comments>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 17:40:49 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[linux commands]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</guid>
		<description><![CDATA[Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files: grep -r Hoffman */*.tex &#124; less +/Hoffman Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression. The &#8220;less&#8221; command has a very [...]]]></description>
			<content:encoded><![CDATA[<p>Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:</p>
<p><code>grep -r Hoffman */*.tex | less +/Hoffman</code></p>
<p>Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression.</p>
<p>The &#8220;less&#8221; command has a very convenient argument &#8220;+&#8221; which allows you to pass a search term in and will automatically highlight it for you.</p>
<p>The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.</p>
<p>sweet.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2007%2F07%2F15%2Fsweet-search-and-highlight-command%2F&amp;title=Sweet%20Search%20And%20Highlight%20Command" id="wpa2a_4"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

