<?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>Random Wisdom &#187; file processing</title>
	<atom:link href="http://scrolls.mafgani.net/tag/file-processing/feed/" rel="self" type="application/rss+xml" />
	<link>http://scrolls.mafgani.net</link>
	<description>An attempt at organizing my thoughts ...</description>
	<lastBuildDate>Tue, 13 Apr 2010 18:17:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Create links with absolute paths in Linux</title>
		<link>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/</link>
		<comments>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 19:10:18 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=420</guid>
		<description><![CDATA[The default behaviour of the linking command (ln) is a little strange under certain circumstances. Since it creates the links using the literal value of the target, symbolic links created using relative path structures can often fail. Consider the following: $ ln -s targetfile ../src/targetfile_link Without a doubt, &#8216;targetfile_link&#8217; will be a broken symlink since [...]]]></description>
			<content:encoded><![CDATA[<p>The default behaviour of the linking command (<strong>ln</strong>) is a little strange under certain circumstances. Since it creates the links using the literal value of the target, symbolic links created using relative path structures can often fail. Consider the following:</p>
<pre>$ ln -s targetfile ../src/targetfile_link</pre>
<p>Without a doubt, &#8216;targetfile_link&#8217; will be a broken symlink since it links to a target that it assumes is in the same directory:</p>
<pre>$ cd ../src &amp;&amp; ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 5 2010-01-16 18:19 targetfile_link -&gt; targetfile</pre>
<p>This is quite unfortunate since it clearly clashes with the way that the linking mechanism should work intuitively.</p>
<p>The solution is to force <strong>ln</strong> into automatically appending the absolute path to the target files. This can be achieved by using a simple shell script that acts as a wrapper for the real linking command:</p>
<pre style="color: #99ccff">
#!/bin/sh

# Step through the supplied arguments and append the absolute
# path to targets that exist
for ARG in $@
do
  if [ -e $ARG ]; then
    LNARGS="${LNARGS} ${PWD}/${ARG}";
  else
    LNARGS="${LNARGS} ${ARG}";
  fi
done

# Execute the actual link command with the modified args
exec /bin/ln ${LNARGS};
</pre>
<p>There are two known caveats:</p>
<ul>
<li> The link is &#8216;sub-optimal&#8217; if created from within the destination directory (the absolute path contains &#8216;../&#8217;s). It will still work however.</li>
<li>  The links will always be absolute. If that is undesirable, save the script as &#8216;absln&#8217; or something other than &#8216;ln&#8217;.</li>
</ul>
<p>Using &#8216;absln&#8217; instead of &#8216;ln&#8217; in the previously described scenario now produces a working symlink:</p>
<pre>$ absln -s targetfile ../src/targetfile_link
$ cd ../src/ &#038;&#038; ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 16 2010-01-16 19:13 targetfile_link -> /tmp/files/targetfile</pre>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Graphics format conversion</title>
		<link>http://scrolls.mafgani.net/2009/12/graphics-format-conversion/</link>
		<comments>http://scrolls.mafgani.net/2009/12/graphics-format-conversion/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 01:28:02 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[eps]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[sam2p]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=408</guid>
		<description><![CDATA[Up until now I have been using the &#8216;convert&#8216; tool that comes with ImageMagick to switch between image formats &#8212; mainly for creating EPS files from JPG/PNG (raster format) files for use with LaTeX. Then I came across sam2p. It is a light-weight utility that does one thing only and it does it well: convert [...]]]></description>
			<content:encoded><![CDATA[<p>Up until now I have been using the &#8216;<strong>convert</strong>&#8216; tool that comes with <a href="http://www.imagemagick.org">ImageMagick</a> to switch between image formats &#8212; mainly for creating EPS files from JPG/PNG (raster format) files for use with LaTeX. Then I came across <a href="http://code.google.com/p/sam2p/">sam2p</a>. </p>
<p>It is a light-weight utility that does one thing only and it does it well: convert between image formats. I&#8217;ve been using it for a while now and find that it can greatly reduce files sizes with minimal drop in quality. I&#8217;ve even used it to process existing EPS files just to get the reduction in file size. Best of all, it is multi-platform &#8212; executables are available for both Windows and Linux on the <a href="http://code.google.com/p/sam2p/">project homepage</a>.</p>
<p>Goodbye <strong>convert</strong> and hello <strong>sam2p</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2009/12/graphics-format-conversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Embedding fonts in a PDF document</title>
		<link>http://scrolls.mafgani.net/2008/10/embedding-fonts-in-a-pdf-document/</link>
		<comments>http://scrolls.mafgani.net/2008/10/embedding-fonts-in-a-pdf-document/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 13:08:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[embedding]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[ps]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=100</guid>
		<description><![CDATA[It is often a good idea (or a requirement) to embed the used font faces in a PDF document. This is easily accomplished using ps2pdf during the final stage of conversion of a document from PS to PDF: $ ps2pdf -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 \ -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true \ 'input_file.ps' 'output_file.pdf' An explanation of the command [...]]]></description>
			<content:encoded><![CDATA[<p>It is often a good idea (or a requirement) to embed the used font faces in a PDF document. This is easily accomplished using <span style="font-weight:bold;">ps2pdf</span> during the final stage of conversion of a document from PS to PDF:</p>
<pre>
$ ps2pdf -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 \
         -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true \
         'input_file.ps' 'output_file.pdf'
</pre>
<p>An explanation of the command options can be found in the <span style="font-weight:bold;">Ps2pdf.htm</span> file in the Ghostscript documentations (or <a href="http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm">here</a>).</p>
<p>[<a href="http://www.hamilton.ie/gavinmc/docs/timesinpdfs.html">Source</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2008/10/embedding-fonts-in-a-pdf-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing files using &#8216;find&#8217;</title>
		<link>http://scrolls.mafgani.net/2008/03/processing-files-using-find/</link>
		<comments>http://scrolls.mafgani.net/2008/03/processing-files-using-find/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 15:32:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[find]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=98</guid>
		<description><![CDATA[In its most basic form, find is often used to locate files that are subsequently piped through a complex set of commands for processing. However, this particular method is easily broken by files that contain spaces in their names. This is where the &#8216;exec&#8217; option provided by find comes in handy. From the man-page: -exec [...]]]></description>
			<content:encoded><![CDATA[<p>In its most basic form, <span style="font-weight:bold;">find</span> is often used to locate files that are subsequently piped through a complex set of commands for processing. However, this particular method is easily broken by files that contain spaces in their names.</p>
<p>This is where the <span style="font-style:italic;">&#8216;exec&#8217;</span> option provided by <span style="font-weight:bold;">find</span> comes in handy. From the man-page:</p>
<pre>
-exec command ;
       Execute  command;  true  if 0 status is returned.  All following
       arguments to find are taken to be arguments to the command until
       an  argument  consisting of ‘;’ is encountered.  The string ‘{}’
       is replaced by the current file name being processed  everywhere
       it occurs in the arguments to the command, not just in arguments
       where it is alone, as in some versions of find.  Both  of  these
       constructions might need to be escaped (with a ‘\’) or quoted to
       protect them from expansion by the shell.  See the EXAMPLES sec-
       tion  for examples of the use of the ‘-exec’ option.  The speci-
       fied command is run once for each matched file.  The command  is
       executed  in  the  starting  directory.    There are unavoidable
       security problems surrounding  use  of  the  -exec  option;  you
       should use the -execdir option instead.
</pre>
<p>An example that recursively touches all *.log files from the current directory would be:</p>
<pre>
$ find . -name \*.log -exec touch {} \;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2008/03/processing-files-using-find/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mass conversion of images</title>
		<link>http://scrolls.mafgani.net/2007/05/mass-conversion-of-images/</link>
		<comments>http://scrolls.mafgani.net/2007/05/mass-conversion-of-images/#comments</comments>
		<pubDate>Mon, 07 May 2007 22:00:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[multimedia]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=85</guid>
		<description><![CDATA[The following &#8220;one-liner&#8221; can be used to mass convert a given image format into another using the convert (part of ImageMagick) and basename tools: $ for A in $(ls *.$SRC_TYPE); do convert $A $(basename $A .$SRC_TYPE).$DST_TYPE; done where $SRC_TYPE is the file suffix of the original images (e.g. png) and $DST_TYPE is the file suffix of the [...]]]></description>
			<content:encoded><![CDATA[<p>The following &#8220;one-liner&#8221; can be used to mass convert a given image format into another using the <i>convert</i> (part of <strong>ImageMagick</strong>) and <i>basename</i> tools:</p>
<pre>$ for A in $(ls *.$SRC_TYPE); do convert $A $(basename $A .$SRC_TYPE).$DST_TYPE; done</pre>
<p>where <span style="font-family:courier new;">$SRC_TYPE</span> is the file suffix of the original images (e.g. <i>png</i>) and <span style="font-family:courier new;">$DST_TYPE</span> is the file suffix of the type desired (e.g. <i>eps</i>).</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2007/05/mass-conversion-of-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cropping a PDF Document</title>
		<link>http://scrolls.mafgani.net/2006/07/cropping-a-pdf-document/</link>
		<comments>http://scrolls.mafgani.net/2006/07/cropping-a-pdf-document/#comments</comments>
		<pubDate>Mon, 31 Jul 2006 20:29:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[pdftops]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=70</guid>
		<description><![CDATA[Easily accomplished using pdftops: $ pdftops -paperw WIDTH \ -paperh HEIGHT \ -noshrink -expand document.pdf &#38;&#38; ps2pdf document.ps WIDTH and HEIGHT are in points &#8212; they basically specify the dimensions of the image to be cropped. Content is extracted from the center of the page. This technique is specially useful as a bypass for using [...]]]></description>
			<content:encoded><![CDATA[<p>Easily accomplished using <span style="font-style: italic;"><a href="http://www.die.net/doc/linux/man/man1/pdftops.1.html">pdftops</a></span>:</p>
<pre>
$ pdftops -paperw WIDTH \
             -paperh HEIGHT \
             -noshrink -expand document.pdf &amp;&amp; ps2pdf document.ps
</pre>
<p>WIDTH and HEIGHT are in points &#8212; they basically specify the dimensions of the image to be cropped.</p>
<p>Content is extracted from the center of the page. This technique is specially useful as a bypass for using <span style="font-style: italic;"><a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/psfrag.html">psfrag</a></span> with pdfLatex:</p>
<ul>
<li>Save EPS figure with TAGS</li>
<li>Create a very simple tex document that simply includes the figure (centered) with psfrag replacements and run latex -> dvips -> ps2pdf</li>
<li>Follow the step above to crop out the figure.</li>
</ul>
<p>The cropped out figure will have the TAGS replaced and be in PDF format &#8212; ready to be used with pdfLatex!</p>
<p><span style="font-weight: bold;">UPDATE [16 July 2009]</span> It looks like <span style="font-style: italic;">pdfcrop</span> might actually be a better option:</p>
<pre>
$ pdfcrop --help
PDFCROP 1.5, 2004/06/24 - Copyright (c) 2002, 2004 by Heiko Oberdiek.
Syntax:   pdfcrop [options] &lt;input[.pdf]&gt; [output file]
Function: Margins are calculated and removed for each page in the file.
Options:                                                    (defaults:)
  --help              print usage
  --(no)verbose       verbose printing                      (false)
  --(no)debug         debug informations                    (false)
  --gscmd &lt;name&gt;      call of ghostscript                   (gs)
  --pdftexcmd &lt;name&gt;  call of pdfTeX                        (pdftex)
  --margins "&lt;left&gt; &lt;top&gt; &lt;right&gt; &lt;bottom&gt;"                 (0 0 0 0)
                      add extra margins, unit is bp. If only one number is
                      given, then it is used for all margins, in the case
                      of two numbers they are also used for right and bottom.
  --(no)clip          clipping support, if margins are set  (false)
  --(no)hires         using `%%HiResBoundingBox'            (false)
                      instead of `%%BoundingBox'
  --papersize &lt;foo&gt;   parameter for gs's -sPAPERSIZE=&lt;foo&gt;,
                      use only with older gs versions &lt;7.32 ()
Examples:
  pdfcrop --margins 10 input.pdf output.pdf
  pdfcrop --margins '5 10 5 20' --clip input.pdf output.pdf
</pre>
<p>The tool comes as a part of the &#8216;tetex&#8217; package.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2006/07/cropping-a-pdf-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prosper &amp; PDF Output</title>
		<link>http://scrolls.mafgani.net/2006/02/prosper-pdf-output/</link>
		<comments>http://scrolls.mafgani.net/2006/02/prosper-pdf-output/#comments</comments>
		<pubDate>Fri, 24 Feb 2006 12:33:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[prosper]]></category>
		<category><![CDATA[ps2pdf]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=57</guid>
		<description><![CDATA[Prosper cannot be used with PDFTeX and hence PDF files must be obtained via the DVI -> PS -> PDF route. The default ps2pdf conversion, however, generates a PDF with pages that are a bit too narrow. This is easily remedied by specifying the size of the output desired to the ps2pdf program: $ ps2pdf [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold;"><a href="http://prosper.sf.net">Prosper</a></span> cannot be used with <span style="font-weight: bold;">PDFTeX</span> and hence PDF files must be obtained via the <span style="font-weight: bold;">DVI -> PS -> PDF</span> route. The default <span style="font-weight: bold;">ps2pdf</span> conversion, however, generates a PDF with pages that are a bit too narrow. This is easily remedied by specifying the size of the output desired to the <span style="font-weight: bold;">ps2pdf</span> program:</p>
<pre>$ ps2pdf -dDEVICEWIDTHPOINTS=x -dDEVICEHEIGHTPOINTS=y somefile.ps</pre>
<p>Where &#8216;x&#8217; is the width in and &#8216;y&#8217; is the height in 1/72&#8243; units. So, for an approximately A4 size output, &#8216;x&#8217;=595 &amp; &#8216;y&#8217;=842.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2006/02/prosper-pdf-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PSfrag for EPS Graphichs Text Manipulation</title>
		<link>http://scrolls.mafgani.net/2006/01/psfrag-for-eps-graphichs-text-manipulation/</link>
		<comments>http://scrolls.mafgani.net/2006/01/psfrag-for-eps-graphichs-text-manipulation/#comments</comments>
		<pubDate>Tue, 17 Jan 2006 11:20:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[eps]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[labelling]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[psfrag]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=48</guid>
		<description><![CDATA[There&#8217;s a nice package called psfrag that allows you to insert LaTeX constructs into EPS figures. This is specially useful with EPS files saved from MATLAB plots. The way it works is by replacing a given tag in the text of the EPS file with the LaTeX construct. E.g. label the x-axis of of the [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a nice package called <span style="font-weight:bold;">psfrag</span> that allows you to insert LaTeX constructs into EPS figures. This is specially useful with EPS files saved from MATLAB plots. The way it works is by replacing a given tag in the text of the EPS file with the LaTeX construct.</p>
<p>E.g. label the x-axis of of the plot as XLABEL and save the plot as an EPS file. Then, when you include that file, just put in the \psfrag{}{} tag:</p>
<pre>\psfrag{XLABEL}{$\frac{\tau}{\sigma}$}\includegraphics{file}</pre>
<p>The most obvious disadvantage is that it only works with EPS figures &#8212; so no PdfLaTeX. So, to compile a document to PDF, you&#8217;ll need to go the old latex -> dvi2ps -> ps2pdf way.</p>
<p>More details can be found on <a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/psfrag.html">CTAN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2006/01/psfrag-for-eps-graphichs-text-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
