tag:blogger.com,1999:blog-17656500711522063882024-03-13T16:26:56.989+01:00jevopi's little blogJens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-1765650071152206388.post-18361510369285089412014-02-09T14:31:00.000+01:002014-02-09T16:40:18.550+01:00UPS for Raspberry PiAs described in the previous post, I'm using the Raspberry Pi as a server for my calender and addressbook data. It is directly connected to my WLan station, and I want to be able to simply shutdown both devices by simply switching off power. Simply switching off power is not the best idea for a Linux system. That is, the preferred way is to neatly shutdown the system before. Since I do not want to start a terminal application before in order to shutdown the Pi properly, I found a different solution: <a hrf="http://www.piusv.de"><b>CW2's Pi USV</b></a> (USV is german for UPS). It is a battery powered UPS, which comes with a nice software package for Pi's Debian Linux. The UPS and the software shutdown the system when the USB power supply is switched off. This is exactly what I needed.
<p>
Installation is rather easy. On <a href="http://www.piusv.de">piusv.de</a> you find a short movie demoing the device, along with some PDFs of how to connect the hardware and set up the software (there are <a href="http://www.piusv.de/support/index.php">english manuals</a>, even though the web page is in german language only).
<p>
I have a case for my Pi, and in order to be able to use that case with the UPS, I had to cut three holes as shown in the picture. The installation of the hardware is nicely documented in CW2's manuals.
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-JZxszefgVcA/UveCheOkCNI/AAAAAAAAAMI/3duJWzDuK6E/s1600/CW2PiAndCase.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-JZxszefgVcA/UveCheOkCNI/AAAAAAAAAMI/3duJWzDuK6E/s320/CW2PiAndCase.jpg" /></a></div>
<h4>Software</h4>
CW2 UPS comes with nice software, which monitors the power and automatically shutdown the system if the USB power is switched off. The software comes as a Debian package, and the installation sets up everything -- usually you do not need to manually adjust things.
<p>
This is how I installed the software on command line (as I have no monitor attached to my Pi, I always connect via ssh):
<p>
Download piusvmonitor software on command line via wget:
<pre>wget http://www.piusv.de/support/piusvmonitor.deb</pre>
<p>Install piusvmonitor as super user:
<pre>sudo dpkg --install piusvmonitor.deb</pre>
<p>After installation, you will find a shell script
<pre>piusvautostart</pre>
in /etc/init.d for starting the piusmonitor automatically. After installation, the software is automatically started. The monitor actually is a service, running in the background.
<p>
Configuration and log files are found in
<pre>/usr/share/piusvmonitor</pre>
<p>Check functionality:
<pre>tail -f /usr/share/piusvmonitor/log.piusv</pre>
Initially:
<small>
<pre>
Sun Feb 9 12:21:38 2014
PRI_POW
</pre>
</small>
Now, remove one battery as shown on the demo on
<a href="http://www.piusv.de/index.php#home">pisv.de</a>:
This will be shown in the log:
<small><pre>
Sun Feb 9 12:21:39 2014
PRI_POW BAT_LOW
Sun Feb 9 12:21:39 2014
PRI_POW BAT_LOW
</pre></small>
Now, put battery back:
<small><pre>
Sun Feb 9 12:21:53 2014
PRI_POW
Sun Feb 9 12:21:53 2014
PRI_POW
</pre></small>
Eventually, try the shutdown by removing the USB power supply:
<small><pre>
Sun Feb 9 12:22:02 2014
SEC_POW BAT_LOW
Sun Feb 9 12:22:02 2014
SEC_POW BAT_LOW
Sun Feb 9 12:22:12 2014
PIUSV shutdown
Sun Feb 9 12:22:12 2014
PIUSV shutdown
Sun Feb 9 12:22:16 2014
SEC_POW BAT_LOW
Connection to xxx.xxx.xxx.xxx closed by remote host.
Connection to xxx.xxx.xxx.xxx closed.
</pre></small>
The last two lines a due to the ssh connection, of course.
After rebooting and reconnecting to the PI, the piusv software is started automatically:
<small><pre>
Sun Feb 9 12:22:28 2014
PRI_POW
Sun Feb 9 12:28:20 2014
PRI_POW BAT_LOW
Sun Feb 9 12:28:21 2014
PRI_POW
</pre></small>
<h4>Summary</h4>
The CW2 UPS is a nice little device, and the software is working great. Unfortunately the common Rasperry Pi case does not really fit. Most of all, it would be nice to have a real connector for the battery package instead of the press-stud connection. The CW2 UPS costs about 30€ and can be ordered irectly from CW2. Additionally, you need batteries, of course. Note that the UPS does not automatically charge the batteries, so there is still some "manual" maintenance necessary.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com2tag:blogger.com,1999:blog-1765650071152206388.post-38364918573299752832014-01-12T15:47:00.000+01:002016-05-14T19:17:47.778+01:00Raspberry Pi and ownCloud: Calendar and contact synchronization without Apple or GoogleThe probably badest news about Mac OS X Maverick is that the synchronization services were removed, thus disabling tools like Missing Sync to work. I used Missing Sync to synchronize calendar and contacts between my MacBook and Android phone. Since I do not want to use Google, I had to find another solution.
<br />
My new solution is a combination of the following things:
<br />
<ul>
<li>Raspberry Pi</li>
<li>ownCloud</li>
<li>CalDav- and CardDav-Sync for Android</li>
</ul>
I have a Raspberry Pi running ownCloud connected to my Airport Extreme via Ethernet cable (as it is directly placed near to the Airport). It has a static IP, so that it is easy to find in my local network. For security reasons it is only available in my local network: I don't need global access to my few contact and calendar data, as it is sufficient to sync the data when I (and my Android and MacBook) are at home. ownCloud is a little cloud solution, providing WebDav, CalDav and CardDav services. These services are used to sync the data similar to Google or Apple.
<br />
<h5>
Why a Raspberry Pi?</h5>
For security reasons, I didn't want to use a (virtual) server publicly available on the internet. I simply do not have the time to constantly update a server for fixing security issues. Also, setting up a server in the cloud is not that much different from using Google, is it? Since the server needs to be accessible to the Android device, a static IP address is very convenient. I could have installed ownCloud on my MacBook directly, and assigning the book a static IP address (or reserve a specific DSCP IP address to the MacBook), however with the Pi I can use the server not only for me but also for roommates ;-) And then, for a geek a real local server is simply a must, isn't it?
<br />
<h4>
Setup Raspberry Pi and ownCloud</h4>
Installation if this set up was pretty easy:
<br />
<ol>
<li>Buy a Raspberry Pi along with an USB power supply, an SDHC card, and a little case and maybe little cooling elements</li>
<li>Format SDHC card (luckily my MacBook has an SD card slot) via SD Formatter for Mac (<a href="https://www.sdcard.org/downloads/formatter_4/">https://www.sdcard.org</a>)</li>
<li>Install Rasbian via Noobs (<a href="http://www.raspberrypi.org/downloads">http://www.raspberrypi.org</a>)</li>
<ol>
<li>follow readme instruction foud in Noobs zip</li>
<li>install Rasbian via Noobs, enable SSH via menu</li>
<li>set up static IP address (e.g., see <a href="https://thepihut.com/blogs/raspberry-pi-tutorials/16683276-how-to-setup-a-static-ip-address-on-your-raspberry-pi">https://thepihut.com/blogs/raspberry-pi-tutorials/</a>)</li>
<li>while 3.1-3.3 needed the Pi to be connected to a monitor, once the static IP address is configured, the following steps can be applied via ssh.</li>
</ol>
<li>Install ownCloud (<a href="https://owncloud.com/download">https://owncloud.com</a>), following the tutorial at
<a href="http://www.connect.de/ratgeber/so-installieren-sie-owncloud-auf-einem-raspberry-pi-1540246.html#">http://www.connect.de</a> (german only).
<br />Minor adjustment: The SSL configuration file has to have newlines, that is, use this template:
<pre><virtualhost>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
DocumentRoot /var/www
</virtualhost></pre>
</li>
</ol>
<h4>
Set up clients</h4>
Now, configure ownCloud, that is, set up initial admin user and create a new user via the web interface.
<br />
There is not much magic to configuring CalDav and CardDav to the OS X apps (in the apps, select preferences and add your own server using the static IP address and the configured user).<br />
There may be some trouble setting up CardDav. For El Capitan, add a new CardDav account, manual setup, and use the following server address:<br />
<pre>
https://SERVER/owncloud/remote.php/dav/principles/users/USERNAME
</pre>
<br />
<br />
<br />
For initial import of the calendar entries, export your calendar to a file. This file is then uploaded via drag'n drop to ownCloud and imported there via click (only click once, this might take a while).
<br />
The last point has been a little bit tricky, as I had to create a temporary folder manually in order make it work. This is how I did it:
<br />
<pre>cd /var/www/apps/calendar/
sudo mkdir import_tmp
sudo chown www-data:www-data import_tmp
</pre>
<h5>
Android Apps</h5>
I'm using the following Android apps now (instead of the Missing Sync software with Fliq Calendar, which I never really liked):
<br />
<ul>
<li><a href="https://play.google.com/store/apps/details?id=org.dmfs.caldav.lib&hl=de">CalDav</a></li>
<li><a href="https://play.google.com/store/apps/details?id=org.dmfs.carddav.sync">CardDav</a></li>
<li><a href="https://play.google.com/store/apps/details?id=netgenius.bizcal&hl=de">Business Calendar</a></li>
</ul>
<small>(Thank you Marcus for pointing me to these apps!)</small>
Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-42505891216582456672011-10-06T17:16:00.001+01:002012-02-26T15:18:18.010+01:00Latex listings definitions for modeling languagesSeems as if the Latex <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/listings/">listings package</a> does not let me go...<br />
<br />
After blogging about how to <a href="http://jevopi.blogspot.com/2010/03/nicely-formatted-listings-in-latex-with.html">nicely format listing</a> with the Latex listings package, using a <a href="www.eclipse.org">Eclipse</a> syntax coloring style, and solving some tiny yet annoying problems with <a href="http://jevopi.blogspot.com/2010/04/latex-lstinline-and-hyphenations.html">hyphenations of inline listings</a> and <a href="http://jevopi.blogspot.com/2010/05/latex-listings-and-labels.html">labels within listings</a>, I have compiled a couple of language definitions for (Eclipse) modeling languages.<br />
<br />
Actually, these definitions are rather small, as they basically contain a list of keywords of a language. Besides the language definition, I usually define a command for quickly writing some inline listing code. I have explained this command in an <a href="http://jevopi.blogspot.com/2010/04/latex-lstinline-and-hyphenations.html">earlier blog posting</a>.<br />
<br />
So, here are the definitions for QVT, ATL, ETL, Xtend, and Xtext.<br />
<br />
<h4><a href="http://www.omg.org/spec/QVT/1.0/">QVT</a> -- Query, View, Transformations</h4><pre class="shadowbox">\lstdefinelanguage{QVT}{
morekeywords={
% relations:
checkonly, domain, enforce, extends, implementedby, import,
key, overrides, primitive, query, relation, top,
transformation, when, where
% operational:
Bag, Collection, Dict, OrderedSet, Sequence, Set, Tuple, abstract,
access, and, any, assert, blackbox, break, case, class, collect,
collectNested, collectOne, collectselect, collectselectOne,
composes, compute, configuration, constructor, continue, datatype,
default, derived, disjuncts, do, elif, else, end, endif,
enum, except, exists, extends, exception, false, forAll, forEach ,
forOne, from, helper, if, implies, import , in, inherits, init,
inout, intermediate, invresolve, invresolveIn, invresolveone,
invresolveoneIn , isUnique, iterate, late, let, library, literal,
log, main, map, mapping, merges, metamodel, modeltype, new, not,
null, object, one, or, ordered, out, package, population, primitive, property,
query, raise, readonly, references, refines, reject, resolve, resolveIn, resolveone,
resolveoneIn, return, select, selectOne, sortedBy, static,
switch, tag, then, transformation, true, try, typedef, unlimited,
uses, var, when, where, while, with, xcollect , xmap, xor, xselect
},
keywordstyle=[2]{\textbf},
morecomment=[l]{--},
morestring=[b]{'},
tabsize=4}
\newcommand{\lstQVT}[1]{\lstinline[language=QVT,breaklines=true,basicstyle=\listingsfontinline,mathescape,literate={\-}{}{0\discretionary{-}{}{}}]§#1§}</pre><br />
<h4><a href="http://www.eclipse.org/atl/">ATL</a> -- Atlas Transformation Language</h4><pre class="shadowbox">\lstdefinelanguage{ATL}{
morekeywords={true,false,
Bag,Set,OrderedSet,Sequence,Tuple,Integer,Real,Boolean,String,TupleType,
not,and,or,xor,implies,module,create,from,uses,helper,def,context,
rule,using,derived,to,mapsTo,distinct,
foreach,in,do,if,then,else,endif,let,
library,query,for,div,refining,entrypoint},
keywordstyle=[2]{\textbf},
morecomment=[l]{--},
morestring=[b]{'},
tabsize=4}
\newcommand{\lstATL}[1]{\lstinline[language=ATL,breaklines=true,basicstyle=\listingsfontinline,mathescape,literate={\-}{}{0\discretionary{-}{}{}}]§#1§}</pre><br />
<h4><a href="http://www.eclipse.org/gmt/epsilon/doc/etl/">ETL</a> -- Epsilon Transformation Language</h4><pre class="shadowbox">\lstdefinelanguage{ETL}{
morekeywords={true,false,
pre, rule, operation,
var, transform,to,
select, selectOne, all,
@greedy,
for,if,else,
not,and,or,
Any,String,Boolean,
true,false,return},
keywordstyle=[2]{\textbf},
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
tabsize=4}
\newcommand{\lstETL}[1]{\lstinline[language=ETL,breaklines=true,basicstyle=\listingsfontinline,mathescape,literate={\-}{}{0\discretionary{-}{}{}}]§#1§}</pre><br />
<br />
<h4><a href="http://www.eclipse.org/modeling/m2t/?project=xpand">Xtend</a> 1.0.1</h4><pre class="shadowbox">\lstdefinelanguage{Xtend}{
morekeywords={cached,case,default,extension,false,import,JAVA,WORKFLOWSLOT,let,new,null,private,create,switch,this,true,reexport,around,if,then,else,context},
keywordstyle=[2]{\textbf},
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
tabsize=4}
\newcommand{\lstXtend}[1]{\lstinline[breaklines=true,language=Xtend,basicstyle=\listingsfontinline,mathescape,literate={\-}{}{0\discretionary{-}{}{}}]\S#1\S}</pre><br />
<h4><a href="http://www.eclipse.org/Xtext/">Xtext</a> 1.0.1</h4><pre class="shadowbox">\lstdefinelanguage{Xtext}{
morekeywords={grammar, with, hidden, generate, as, import, returns, current, terminal, enum},
keywordstyle=[2]{\textbf},
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
tabsize=4}
\newcommand{\lstXtext}[1]{\lstinline[breaklines=true,language=Xtext,basicstyle=\listingsfontinline,mathescape,literate={\-}{}{0\discretionary{-}{}{}}]\S#1\S}</pre><br />
If you need a new language definition for your own Xtext based modeling or programming or domain specific or whatever language, it is very easy to retrieve the tokens of the language. Within the project of your Xtext grammar file, a special ANTLR file containing all the tokens will be generated. You will find that file in<br />
<pre>src-gen/<my_language_package>/parser/antlr/internal/Internal<mylanguage>.tokens</pre><br />
<h4>Xpand</h4>[Updated February 2012] A friend of mine (thank you, <a href="http://www.jensgulden.de/">Jens</a>!) just sent me a new definition for Xpand:<br />
<pre class="shadowbox">\lstdefinelanguage{Xpand}{
morekeywords={IMPORT, DEFINE, ENDDEFINE, LET, ENDLET, FOR, FILE, ENDFILE, ITERATOR, FOREACH, AS, IF, ENDFOREACH, ENDIF, EXPAND, INSTANCEOF, USING, SEPARATOR, CSTART, CEND, PROTECT, ENDPROTECT, ID, EXTENSION, ERROR, WARNING, INFO},
inputencoding=latin1,
extendedchars=true,
% note: first and last guillemot of comments will not appear in comment style, guillemots are not possible in delimiters
morecomment=[s]{REM}{ENDREM},
morestring=[s]{"}{"},
% for use with UTF-8
literate={«}{\guillemotleft}{1}
{»}{\guillemotright}{1}
}
</pre>This definition is a slight modification of the definitions posted in the <a href="http://www.eclipse.org/forums/index.php/m/538361/">Eclipse M2T forum</a> (and also at <a href="http://trac.rtsys.informatik.uni-kiel.de/trac/rtsys/wiki/Latex/Examples/Listings">the Rtsys Group Wiki, Uni Kiel</a>) a while ago.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com1tag:blogger.com,1999:blog-1765650071152206388.post-78968488497654948962011-07-23T19:01:00.001+01:002011-07-23T19:02:58.028+01:00Pimp your KindleI really like the idea of ebooks. These E Inks displays have an astonishing quality: I was very surprised to be even able to read a Din A4 PDF, downsized to fit the 6 inch display of a Kindle---although it is hard to read.<br />
<br />
So, as I like the idea, I bought an ebook reader. I decided to buy Amazon's Kindle reader, as there are a lot of ebooks available thanks to Amazon. While I'm still enthusiastic about the really good display, I'm completely disappointed in the Kindle software. Most of all, ebooks are always displayed using justified text. But since hyphenation is not supported, this leads to really ugly layouts. The combination of justified text without hyphenation is a show-stopper! <br />
<br />
So, I tried to figure out a solution to that problem. Fortunately, I found a Kindle version of the FBReader (fbkindle), which is not too complicated to be installed on the Kindle. FBReader displays ebooks in epubs format, and it provides hyphenation as known from TeX. Really nice! This blog entry summarizes the necessary steps along with a short presentation of additional tips.<br />
<br />
<h3>Motivation</h3><br />
Before explaining the necessary steps to install FBReader, I just want to show you the differences between the original Kindle AZW reader and the FBReader. <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-_Yu9iGVU_xE/TisGmM7tvNI/AAAAAAAAAHM/LqWjOLzxeKE/s1600/kindleVSfbreader.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="266" width="320" src="http://3.bp.blogspot.com/-_Yu9iGVU_xE/TisGmM7tvNI/AAAAAAAAAHM/LqWjOLzxeKE/s320/kindleVSfbreader.png" /></a><br />
Figure 1: Comparison of original Kindle AZW reader (left) and FBKindle epub reader (right)</div><br />
Figure 1 shows two scans of the Kindle. I have used Melville's Moby Dick (<a href="https://www.amazon.de/Moby-Dick-White-Whale-ebook/dp/B004TRXX7C/ref=sr_1_1?ie=UTF8&qid=1311428734&sr=8-1">free Amazon</a> vs. <a href="http://www.feedbooks.com/book/54/moby-dick">Feedbooks</a> version). It is freely available, not only at Amazon but also at some other ebook sites, and besides it is one book I always wanted to read. While some of the differences stem from the information stored in the ebooks themselves, other things are only (missing) features of the reader software. However, in my experience, the example is rather a typical one: I've found much worse (free) ebooks, and also slightly better ones. Let's go into the details:<br />
<br />
The first obvious thing is hyphenation. As said above, the Kindle cannot hyphenate, which is a real problem due to the justified text layout used. The worst thing about that is, that it sometimes produces pseudo paragraphs, as you can see in the circle marked with "1a" (and also in the second line of the following chapter). FBReader supports hyphenation (circle marked "1b"). This is a software problem and no missing feature of the ebook. That is: No AZW ebook will support hyphenation, at least not with the current Kindle reader software.<br />
<br />
The other differences stem from the ebooks themselves. As the headings demonstrate ("2a" vs. "2b"), the AZW book does not correctly layout the heading. That is, the title of the heading is formatted as plain text. While this is only ugly, I have found free AZW books with footnotes inserted into the plain text without anything indicating the footnote (the free version of Hegel's Logik). An even worse problem is, that some books do not come with no table of contents, and no chapter markers. As indicated with the "3a", the AZW version of Moby Dick does not provide any chapter markers, while the EPUB version does ("3b"). Actually, with out these markers and TOC, an ebook like Moby Dick is not usable at all. Sometime, it is possible to generate TOCs with tools such as Calibre, but, hey guys, I want to read a book, not create and fix it.<br />
<br />
While the FBReader provides a much better layout, I really miss one feature the Kindle reader software provides: dictionary integration. This is a really cool feature, and although is is listed as a planned feature for FBReader, is is not implemented yet. At the moment, I'm using my Android's ColorDict to help me out, just as I used to do when reading books printed on paper. Weird! The dictionary coming with Kindle is an english dictionary, and I have installed a free german-english dictionary, as explained below.<br />
<br />
<h3>Overview</h3><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-6QthyNqUaZ0/TisIjikBMSI/AAAAAAAAAHU/p7F-W6YqUP8/s1600/kindleFolder.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="225" width="320" src="http://1.bp.blogspot.com/-6QthyNqUaZ0/TisIjikBMSI/AAAAAAAAAHU/p7F-W6YqUP8/s320/kindleFolder.png" /></a><br />
Figure 2: Kindle root folder after installing 3rd-party software</div><br />
<br />
<br />
Figure 2 shows my Kindle root folder, with some subfolder created by the software described below. It contains a folder with the collections database and some configuration files of the Kindle AZW reader (1), as well as your content (2). All third-party software is installed on the Kindle by first mounting the Kindle to your PC or Mac, and then by copying some installation file into the mounted root folder (0) (sometimes, this folder is referred to as "/mount/us", on MAc OS X, it is the root folder when you mount your Kindle). Then, the Kindle needs to be rebooted, and when starting up, the software is installed automatically (and the installer is removed). The installer usually creates a folder in the Kindle's root folder. <br />
<br />
Frankly, I really hate to install hacks on the Kindle. So, please Amazon, improve your Kindle software! The hardware is really cool, but the software is rotten! Meanwhile, here's how to install alternative software. Frankly, this is not the first list, and you will find similar lists on the web. One of the best places is the <a href="http://www.mobileread.com/">mobileread.com</a> forum, and <a href="http://www.mobileread.com/forums/showthread.php?t=88004">a list of hacks</a> can be found there as well.<br />
<br />
The quick installation should only serve as a short guide, please read the documentation linked to before installing anything. You may lose warranty when applying the hacks described below, or you may break your Kindle. <b>Use it on your own risk!</b><br />
<br />
<h3>"Jailbreak" for Kindle</h3><br />
A small "security" feature built into the original Kindle software prevents arbitrary 3rd-party software to be installed. So, we first need a special piece of software, to work around this issue. This is the "jailbreak". There exists different software versions of the original Kindle software, and they require different software hacks as well. The Kindle (at the time writing this post) comes with version 3.1. Yifan Lu has published a jailbreak for that version: <br />
<br />
<dl><dt>Download</dt>
<dd><a href="http://yifan.lu/2011/02/21/kindle-3-1-jailbreak/">Yifan Lu's website: Kindle 3.1 Jailbreak</a></dd>
<dt>Quick install</dt>
<dd><ol><li>Unpack <code>kindle-jailbreak.zip</code></li>
<li>Copy installer <code>update_jailbreak_*_*_install</code> matching your kindle version into Kindle's root folder (Fig. 2 (0))</li>
<li>Restart Kindle (<i>Home</i>, <i>Menu</i> - Settings, <i>Menu</i> - Restart</li>
</ol></dd>
<dt>Documentation</dt>
<dd> See download location. </dd> </dl><br />
<br />
The ad-base Kindle is not that easy to jailbreak, and frankly: if you choose to save that little money and accept ads, then do not complain about the original software. However, according to Yifan Lu, some non-ad Kindles also come with the new 3.2.1 software, so here's the link on how to jailbreak this version as well (I didn't try it myself): <a href="http://yifan.lu/2011/06/02/kindle-3-2-1-jailbreak/">Yifan Lu: Kindle 3.2.1 Jailbreak</a> (also see <a href="http://www.mobileread.com/forums/showthread.php?t=135509">thread at mobilreader</a>).<br />
<br />
<h3>Launchpad</h3><br />
In order to be able to start 3rd-party software, you need some launcher software (as there is no command line available by default). Launchpad is a small utility, which enables the user to execute commands after pressing a defined sequence of keys, as demonstrated on this <a href="http://www.youtube.com/watch?v=O4gJbp9XhXs">Youtube video.</a>. Launchpad is available via the mobileread.com forum: <br />
<dl><dt>Download</dt>
<dd><a href="http://www.mobileread.com/forums/showthread.php?t=97636">http://www.mobileread.com/forums/showthread.php?t=97636</a></dd>
<dt>Quick install</dt>
<dd><ol><li>Download and unpack <code>lpad-pkg-001c.zip</code></li>
<li>Copy installer <code>update_launchpad_*_*_install.bin</code> matching your kindle version into Kindle's root folder (Fig. 2 (0))</li>
<li>Restart Kindle (<i>Home</i>, <i>Menu</i> - Settings, <i>Menu</i> - Restart</li>
</ol></dd>
<dt>Documentation</dt>
<dd> See download location. </dd> </dl><br />
After successfully installing launchpad, a new subfolder should have been created in your Kindle's root folder, as shown in Figure 2 (3). Inside that folder, you will find the configuration files </code>*.ini</code> with defined key sequences and commands to be executed. Note that you always have to press <i>Shift</i> before the defined key sequences, and that you have to press all keys one after the other and not all at the same time.<br />
<br />
<h3>FBReader (FBKindle)</h3><br />
Now we are ready to install <a href="http://www.fbreader.org">FBReader</a>, in order to be able to read DRM-free EPUB books on your Kindle. There exist two versions: <a href="http://translate.google.de/translate?hl=de&sl=ru&tl=en&u=http%3A%2F%2Fwww.the-ebook.org%2Fforum%2Fviewtopic.php%3Ft%3D15017">FBReader by Dzha</a> and <a href="http://translate.google.de/translate?hl=de&sl=ru&tl=en&u=http%3A%2F%2Fwww.the-ebook.org%2Fforum%2Fviewtopic.php%3Fp%3D515359%23515359">FBKindle by Andy Wooden</a>. I have chosen FBKindle , as it runs vis-a-vis with the original Kindle reader software, and one can easily switch between both version using a keyboard shortcut. Both versions are ports of the original <a href="http://www.fbreader.org/about.php">C++ FBReader</a> software. Unfortunately, this version has not been updated for quite some time, especially because nice things such as dictionary integration are still missing. Note: There also exists a sourceforge project called FBKindle, unfortunately it does not contain any files yet.<br />
<br />
<dl><dt>Download</dt>
<dd><a href="http://www.mobileread.com/forums/showthread.php?t=107371">http://www.mobileread.com/forums/showthread.php?t=107371</a></dd>
<dt>Quick install</dt>
<dd><ol><li>Download and copy <code>fbKindle-bin.tar.gz</code> into Kindle's root folder (Fig. 2 (0))</li>
<li>Add the following lines to your <code>launchpad/launchpad.ini</code> file (or create launchpad/fbreader.ini containing these line):<br />
<pre>[Actions]
F R = !/mnt/us/fbKindle/goqt.sh FBReader &
U T = !cd /mnt/us; tar zxvf fbKindle-bin.tar.gz; rm fbKindle-bin.tar.gz;echo 101 >/proc/eink_fb/update_display</pre><li>Restart Kindle (<i>Home</i>, <i>Menu</i> - Settings, <i>Menu</i> - Restart) in order to activate new key sequences</li><br />
<br />
<li>Activate FBKindle installation key-sequence, i.e. quickly press <i>Shift</i>, then <i>U</i>, and then <i>T</i>. This will unpack the FBKindle archive, and install FBReader in a subfolder <code>fbKindle</code> on your Kindle, as shown in Fig. 2 (4)</li><br />
<br />
<li>Now, start FBKindle via <i>Shift</i>, then <i>F</i>, and then <i>R</i>. Actually, you will have to restart FBKindle every time after restarting your Kindle!</li><br />
<br />
</ol></dd>
<dt>Documentation</dt>
<dd> See download location,german guide at <a href="http://www.e-reader-forum.de/ebook-reader/amazon-kindle/1765-fbreader-für-kindle-epub-silbentrennung/">e-reader-forum.de</a>. </dd> </dl>Unfortunately, the library management of FBReader/FBKindle is as bad as the the management functions of the original Kindle software. Seriously, I'm wondering how Amazon (or in that case the FBReader programmers) expects user's to install and manage more than 20 books. Anyways, the <i>menu</i> button will activate the FBReader menu, and from there on it should be self explaining (shortcuts are documented on the pages linked to above). The nice thing about FBKindle is, that you can easily switch forth and back between FBReader and the original Kindle software by pressing <i>shift</i> and <i>alt</i> simultaneously. <h3>Free dictionaries for the Kindle software</h3>Back to the original Kindle software. A really nice feature of the Kindle reader is that is comes with integrated dictionary support. Since I usually need english to german translations, I was looking for an english-german dictionary. There exists a lot of free dictionaries, and I found a free solution for the Kindle as well. Michael Sheldon (kudos to Michael) has converted free dictionaries into the mobi-format, which is supported by Kindle.
<dl><dt>Download</dt>
<dd><a href="http://mikeasoft.com/~mike/kindle-dicts/">http://mikeasoft.com/~mike/kindle-dicts/</a></dd>
<dt>Quick install</dt>
<dd><ol><li>Download dictionary file, e.g., English-German.mobi, and place it inside your documents folder </li>
<li>Select this dictionary as your primary dictionary via <i>menu</i> - Settings, <i>menu</i> - Change Primary Dictionary</li>
</ol></dd>
<dt>Documentation</dt>
<dd> <a href="http://blog.mikeasoft.com/2011/01/05/free-as-in-gpl2-translation-dictionaries-for-the-kindle/">Michael Sheldon's blog</a> </dd> </dl><h3>Custom Screensaver</h3>Not really necessary, but nice to have: screensaver with your own pictures. I really do not understand why Amazon does not directly support that feature. So, you have to firstly install a 3rd party screensaver hack. Then, you can copy your own pictures into a folder of the screensaver software.
<dl><dt>Download</dt>
<dd><a href="http://www.mobileread.com/forums/showthread.php?t=97636">http://www.mobileread.com/forums/showthread.php?t=97636</a></dd>
<dt>Quick install</dt>
<dd><ol><li>Download and unpack <code>kindle-ss-0.22.N.zip</code></li>
<li>Copy installer <code>update_ss_0.22.N_*_install.bin</code> matching your kindle version into Kindle's root folder (Fig. 2 (0))</li>
<li>Restart Kindle (<i>Home</i>, <i>Menu</i> - Settings, <i>Menu</i> - Restart</li>
<li>Installer should have created a folder <code>linkss</code>, as shown in Figure 2 (5). Copy your images (600x800 pixels) into the created folder <code>linkss/screensavers</code>.</li>
<li>Restart Kindle (<i>Home</i>, <i>Menu</i> - Settings, <i>Menu</i> - Restart) in order to activate new images.</li>
</ol></dd>
<dt>Documentation</dt>
<dd> See download location. </dd> </dl>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com2tag:blogger.com,1999:blog-1765650071152206388.post-25284518958564607772011-05-11T15:58:00.003+01:002011-05-11T16:13:54.722+01:00Fun with Multiple VPN Connections on Mac OS XDisclaimer: Frankly, I'm neither a Unix nerd nor a network freak. Maybe this is why I prefer using Mac OS X: In most cases things are simply working, or at least some nice graphical interfaces guides me through the network configuration jungle. So, use my tips on your own risk and feel free to write me a comment, if you can explain things better :-)<br />
<br />
Virtual private network (VPN) are one of these things making me nervous without a nice GUI. Fortunately, OS X directly supports all the protocols I need (and thank you, Apple, for supporting the Cisco protocol as of OS X version 10.6). Setting up a VPN is as simple as installing a printer. Maybe even simplier ;-) <br />
<br />
However, there are always new <s>problems</s> challenges waiting, and one of these challenges is the use of multiple VPNs simultaneously. I have the following situation: I can only connect to some local network, which does not allow any internet connections. For that purpose, I have to use a VPN "T" -- the VPN server "TServer" (names are only for simplify reading) is more or less the only thing accessible from that internal network. So, every connection to the internet runs through this VPN.<br />
<br />
Now, I have to connect to a server "S", which only accepts connections from a local network, I call it "FNet". And my VPN server "TServer" is not part of this network "FNet". In order to access this server, I usually start another VPN "F" (with another VPN-server "FServ", virtually placing me (and my machine's IP address) inside the local network "FNet". Unfortunately, I can only connect to "FServ" via the first VPN. So, the question is, how to set up the second VPN?<br />
<br />
Fortunately, it is possible to simply connect to two VPNs simultaneously. All you need to do is simply to configure both VPNs in your network settings. <br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-2iXV4m6VXOU/TcqjEoZPhvI/AAAAAAAAAG8/2hV_BU7QsvI/s1600/MultipleVPNs.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="200" src="http://2.bp.blogspot.com/-2iXV4m6VXOU/TcqjEoZPhvI/AAAAAAAAAG8/2hV_BU7QsvI/s200/MultipleVPNs.png" width="190" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig. 1:Simultaneously connect to multiple VPNs</td></tr>
</tbody></table>I can then firstly connect to the VPN "T", and when this connection is establish I can use it to connect to the second VPN "F". Figure 1 shows the VPN menu in the system menu bar (OS 10.6, with elder versions, things look a bit different, as explained <a href="http://www.maclive.net/sid/186">here</a>).<br />
<br />
Well, this is the easy part. The harder part is to tell the applications which VPN to use. This problem is (almost) the same problem as using different network interfaces (e.g., use the Ethernet connection for some tasks, and a WLan connection for others), as the VPNs create virtual network interfaces. So, it's time to start the console... <code>ifconfig</code> prints out the available network interfaces. E.g., my first VPN "T" has created a new interface called ppp0:<br />
<br />
<pre>ppp0: flags=8051<up,pointopoint,running,multicast> mtu 1444
inet 111.123.123.144 --> 111.123.123.166 netmask 0xffff0000</up,pointopoint,running,multicast></pre><br />
It is not that important to know exactly what you see here. The only important thing is the number <code>111.123.123.144</code> which is the IP-address assigned to my machine for VPN "T".<br />
<br />
After connecting to the second VPN "F", another interface is available, representing the second VPN:<br />
<br />
<pre>utun0: flags=8051<up,pointopoint,running,multicast> mtu 1280
inet 222.123.123.155 --> 222.123.123.177 netmask 0xffffff00</up,pointopoint,running,multicast></pre><br />
Within this second VPN, I've got the IP <code>222.123.123.155</code>. <br />
<br />
So, I have two interfaces and two IP addresses, one for each VPN. This information can be used to tell applications to connect via one specific VPN.<br />
<br />
In my case, I want to make an SSH connection to the server "S", which is only possible from within "FNet", that is, using the second VPN "F". Fortunately, I can tell ssh to use a certain IP address on my local machine. Let's assume <code>222.123.144.144</code> to be the IP address of the server S. This is how to connect to "S" via the second VPN "F":<br />
<br />
<pre>>ssh -b 222.123.123.155 -l theUser 222.123.144.144</pre><br />
in which "theUser" the user login for "S". <code>222.123.123.155</code> is the IP of my machine within FNet (as F virtually places my machine in FNet). Note that you have to use the IP address rather then the name of the server (maybe some geek can tell me how to "update" the DNS stuff accordingly).<br />
<br />
Other applications cannot be configured that easily, in these cases you have to add routing entries to your route table. E.g., instead of using the "-b" option of ssh, I could have added a new route (I found that tip <a href="http://superuser.com/questions/181882/force-an-application-to-use-a-specific-network-interface">here</a>). To add a route, I need to be a super user, so we have to use sudo:<br />
<br />
<pre>>sudo add route 222.123.144.144 222.123.123.155</pre><br />
Now, I can directly connect to S without the "-b" option:<br />
<br />
<pre>>ssh -l theUser 222.123.144.144</pre><br />
Don't forget to delete the route when no longer needed:<br />
<br />
<pre>>sudo delete route 222.123.144.144 222.123.123.155</pre>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com1tag:blogger.com,1999:blog-1765650071152206388.post-50319001235227798542010-11-18T16:22:00.006+01:002010-11-18T16:43:38.092+01:00Problems with TortoiseSVN and authentication (on WinXP)Newer versions of TortoiseSVN may produce errors when repositories reside on servers with unknown (untrusted, whatever) certificates. The very same repositories may be checked out and updated using a command line version (or with Mac tools). The error message may be a little too short and doesn't explain very much:
<pre>
Update
OPTIONS of 'https://my.server.com/my/repository': SSL
negotiation failed: Secure connection truncated (https://my.server.com)
Finished!
</pre>
In order to fix this, you will have to change the underlying method of subversion/Tortoise for communicating with the server. This has to be specified in the server settings. This is a simple text file, hidden somewhere on your system. The easiest way of locating this file is by opening the Tortoise Settings and edit the "Subversion configuration file" (found under "General"). However, this only opens the "config" file, but what we need is the "server" file -- which luckily can be found in the very same folder as the "config" file. On my german Windows XP installation, its path is <code><small>C:\Dokumente und Einstellungen\userid\Anwendungsdaten\Subversion\server</small></code>.
In "server" (pay attention to not accidentally add a ".txt" when saving the file), add a new server group in the group section, and set the http-library to "serf" for that group. E.g.,
<pre>
[groups]
myserver = my.server.com
[myserver]
http-library = serf
</pre>
Now, TortoiseSVN should work with your server.
<p>
P.S.: I found the solution at <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=507374">http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=507374</a> (although I have no debian system, it solved my problem, so thank for the tip, Peter Samuelson) ;-). I adapted the solution for TortoiseSVN, as it fixes the problem with TortoiseSVN, and most TortoiseSVN forums suggest to downgrade to elder TortoiseSVN versions, which didn't worked in my case.
</p>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-34263942142943872812010-09-21T14:56:00.004+01:002010-09-21T15:58:53.952+01:00Mount Samsung GT-i5800 as an USB DriveToday I wanted to sync some of my music files with my new GT-i5800. Unfortunately, it didn't worked with MissingSync via Wi-Fi, so I tried USB. Well, how do I mount my GT-i5800 as a USB drive on OS X? By default, USB settings are "Samsung Kies", which I do not need on OS X (and with MissingSync). This setting has to be changed to "Mass storage" <em>before</em> connecting the USB cable!
<pre>Settings > About phone > USB settings > (X) Mass storage (default: Samsung Kies)</pre>
or in german: <pre>Einstellungen > Telefoninfo > USB-Einstellungen > (X) Massenspeicher</pre>
Only after changing this setting, you can connect the GT-i5800 as described in the Missing Sync manual: "pull down the notification window (aka ‘window shade’) and tap USB connected."
<p>
Well, and thanks to <a href="http://www.btunesmusicplayer.com/">bTunes</a> ($1.49), my Android device almost feels like an iPod :-DJens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-32097395693680262882010-09-16T11:42:00.008+01:002010-09-17T13:46:28.402+01:00Android on Samsung GT-I5800 and Mac OS XEventually I had to admit being a geek. As a consequence, I'm an owner of a Samsung Galaxy 3 i5800 (or simply GT-I5800) now. I'm extremely impressed: This Android phone costs 200€ only, and frankly I don't know why to spent 1000€ for an iPhone. Moreover, to me the iPhone is a little bit too big. The i5800 is a little bit smaller, thus it better fits in my trouser pocket. OK, the camera (3.2 MP) is just good enough for funny apps such as the <a href="http://code.google.com/p/zxing/">Barcode Scanner</a>, but I do not really need a camera in my phone.
As I'm an Mac OS X user, the most important thing is syncing with my MacBook Pro. This is really easy thanks to <a href="http://www.markspace.com/products/android/missing-sync-android.html">Missing Sync</a>: Address Book contacts (with photos), iCal calendars, iTunes, iPhoto , arbitrary folders, SMS logs, phone logs, and other things (and in future versions bookmarks) are easily synced via WLan. It can be configured in order to sync automatically every <i>n</i> minutes via WLan or manually. IMHO, this app is worth it's 39$.
Most of my friends have iPhones. So I knew about some great apps they demonstrated me on their gadgets. I'm really surprised finding all these apps available for Android as well and nicely working on my GT-I5800:<ul>
<li><a href="https://www.dropbox.com/android">Dropbox</a> for file syncing</li>
<li><a href="http://blog.agile.ws/post/777806427/1password-is-available-for-android">1Password</a> password manager, can be used in combination with Dropbox!</li>
<li><a href="http://www.callabike-interaktiv.de/index.php?id=189">Call-a-Bike</a>, great for finding a free bike nearby.</li>
<li><a href="http://www.shazam.com/music/web/pages/android.html">Shazam</a> to find out which song is currently played</li>
<li><a href="http://www.bahn.de/p/view/buchung/mobil/railnavigator.shtml">DB Railnavigator</a></li>
<li><a href="http://hyperfine.com/remoteforitunes/default.aspx">Remote for iTunes</a>: With this app I have remote access to my iTunes library on my mac (via WLan), and thanks to my Airport Express I can now listen to my music w/o having to jump back to my computer (in another room) for selecting a new album. I can even select the speakers via this app.</li>
</ul>
Other applications for the daily information overkill:<ul>
<li>I'm still not that happy with the browser (I tried the build in browser and <a href="http://home.dolphin-browser.com/tunny/Home.htm">Dolphin</a>, and I probably will have to spend some time getting along with the latter one as it provides an ad-blocker and reader plugin).</li><li>For RSS, I installed <a href="http://noinnion.com/">gReader Pro</a>. It uses my Google Reader settings, so that I do not have to configure all RSS feeds on the phone. Actually, it is one of the rare things I'm using my Google account for on my phone. </li><li>As a twitter client, I have installed <a href="http://twidroyd.com/">Twidroyd Pro</a>. Seems as if you have to pay a few bucks for good apps.</li><li>As I have mulitple mail accounts, I installed the <a href="http://code.google.com/p/k9mail/">K9</a> mail reader. It is free, and it does what it says. </li>
</ul>
However I'm not feeling comfortable with having my mail account passwords (and others) stored on the phone. Actually, the mail account password is one of the most sensible passwords. If one cracks the mail account, it is quite simple to change other passwords of web applications as most web apps sends you a new password if you have forgotten your old one. The lock method of Android 2.1 (which is not too secure, see <a href="http://www.usenix.org/events/woot10/tech/full_papers/Aviv.pdf">this paper</a>, however, PINs wouldn't solve that problem, would they?) may help, but I'm not really convinced about that issue. I definitely have to investigate further into that topic.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-46167485809518813382010-05-24T12:07:00.011+01:002010-05-24T16:12:39.594+01:00LaTeX: Listings and labelsI have blogged about the <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/listings/">listing package</a> here several times (<a href="http://jevopi.blogspot.com/2010/03/nicely-formatted-listings-in-latex-with.html">nicely formatting</a>, and <a href="http://jevopi.blogspot.com/2010/04/latex-lstinline-and-hyphenations.html">hyphenations</a>). This time I will write about creating labels inside a listing. First of all, the listing package allows to define a caption and a label for a listing, e.g.:
<code><pre>
\begin{lstlisting}[caption={myListing},label={lst:myListing}]
void foo(int x) {
doSomething();
doMore();
}
\end{lstlisting}
</pre></code>
Now the listing can be referenced via <code>\ref{lst:myListing}</code>. The listing package also nicely supports line numbers, there are a whole bunch of settings for that. But why do we need line numbers? In most cases, line numbers are used to refer to a certain line within a listing. E.g, we maybe want to write something like
<blockquote>In line 2 of the listing 1 we call method 'doSomething'.</blockquote>
Well, "listing 1" will look like "<code>listing \ref{lst:myListing}</code>" in the LaTeX source code, but how do we reference the line? Fortunately, the listing packages allows us to escape to latex inside a listing and add a label which can then be referenced:
<code><pre>
\begin{lstlisting}[caption={myListing},label={lst:myListing},numbers=left,escapeinside={@}{@}]
void foo(int x) {
@\label{lst:myListing_2}@doSomething();
doMore();
}
\end{lstlisting}
</pre></code>
Now we can reference the line: <code>In line \ref{lst:myListing_2} ...</code>
Actually, you can use any label text, however I usually use the listings label with the line number or a small marker, in order to avoid conflicts with duplicate labels.
As I do not want to write "line..." and "listing ..." over and over again, I use the <code>autoref</code> command from the <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/">hyperref package</a>:
<code><pre>
In \autoref{lst:myListing_2} of \autoref{lst:myListing}
</pre></code>
<code>autoref</code> automatically adds a name to the reference counter. As there is no name defined for line numbers, it has to be defined previously:
<code><pre>
\providecommand*{\lstnumberautorefname}{line}
</pre></code>
If you need names in a another language, you can add a translation:
<code><pre>
\addto\extrasngerman{%
\def\lstlistingautorefname{Quellcode}%
\def\lstnumberautorefname{Zeile}%
}
</pre></code>
OK, we can add a line label and easily create a reference to that label.
However, writing line labels means a lot of work, especially if you use a listing relative name pattern. So, let's add a macro to <a href="http://texshop.org/">TeXShop</a>, which uses some shell commands (mainly sed) and AppleScript in order to automatically create the label, even adding the line number to the label:
<div style="width:97%; height:200px; overflow:auto;"><code><pre>
--Applescript direct
--
-- Create a label inside a listing, must be invoked at the position at which the label is
-- to be created.
-- Precondition: the listing is defined inside a lstlisting environment and
-- a label is defined in the parameter list of the environment (label={..}).
--
-- New newly created label consists of the label of the listing with the line number
-- appended to the label. You can configure escape characters (as specified in
-- escapeinside={..}{..}) and the separator between listing label and line number.
--
-- E.g. label={myListing}, on line 5 leads to the following output:
-- @\label{lst: myListing!5}@
--
-- (C) 2010 Jens von Pilgrim, http://jevopi.blogspot.com
property texapp : "TeXShop"
property escapeLeft : "@"
property escapeRight : "@"
property separator : "_"
property maxLength : 2000
try
tell application texapp
if texapp = "TeXShop" then
tell application "TeXShop" to set pos to the offset of the selection of the front document
tell application "TeXShop" to set currentSelection to the content of the selection of the front document
else if texapp = "iTeXMac" then
-- ??
end if
set start to 1
if (pos > maxLength) then
set start to pos - maxLength
end if
set preceeding_text to (characters start thru pos of (the text of the front document)) as string
set preceeding_text to my findAndReplace(preceeding_text, "\\", "_")
set lineNumbers to do shell script ¬
"echo " & the quoted form of preceeding_text & ¬
"| sed -n '/label[:space:]*=[:space:]*{[^}]*}/=;$ {x;=;}'"
set theLines to my splitLines(lineNumbers) -- as list
set currentLine to last item of theLines as integer
-- set startLine to item ((length of theLines) - 1) of theLines as integer
-- length is not working when executed as macro... workaround:
set startLine to first item of (rest of (reverse of theLines))
set lstLine to currentLine - startLine
set lastLabel to do shell script ¬
"echo " & the quoted form of preceeding_text & ¬
"| sed -n '/label[:space:]*=[:space:]*{[^}]*}/h;$ {x;p;}'" & ¬
"| sed -n 's/.*label[:space:]*=[:space:]*{\\([^}]*\\)}.*/\\1/g;p'"
set newSelection to escapeLeft & "\\label{" & lastLabel & separator & lstLine & "}" & escapeRight & currentSelection
if texapp = "TeXShop" then
tell application "TeXShop" to set the selection of the front document to newSelection
else if texapp = "iTeXMac" then
--tell application "iTeXMac" to insert new_section in the text of the front document
end if
end tell
on error errmesg number errn
beep
display dialog errmesg
return
end try
on findAndReplace(strInString, strFind, strReplace)
set ditd to text item delimiters
set text item delimiters to strFind
set textItems to text items of strInString
set text item delimiters to strReplace
if (class of strInString is string) then
set res to textItems as string
else -- if (class of TheString is Unicode text) then
set res to textItems as Unicode text
end if
set text item delimiters to ditd
return res
end findAndReplace
on splitLines(strInString)
set ditd to text item delimiters
set text item delimiters to "
"
set textItems to text items of strInString
set text item delimiters to ditd
return textItems
end splitLines
</pre></code></div>
Now things are really easy: Simply activate the macro at the appropriate location in the listing, and a new label will automatically be created. Note: The listing must have a label defined! You can configure the script by changing the properties at the beginning of the macro.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com3tag:blogger.com,1999:blog-1765650071152206388.post-89952725217440597512010-04-20T15:01:00.003+01:002023-01-13T13:10:16.850+01:00LaTeX: Lstinline and HyphenationsI really like the LaTeX <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/listings/">listing package</a>. However, there is one serious problem: Hyphenations are not supported (Option <code>breakline</code> does not break words)! Fortunately I found a solution which is not 100% perfect, but almost (let's say 99% ;-) ). The idea is to use the replacement feature of listings in combination with the discretionary command. Actually, this is not my idea, its <a href="http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2007-05/msg01828.html">Andrei Alexandrescu's</a> idea. I slightly modified his solution. So, here it is. Actually I define a new command for inline Java code -- you may do this using a style, but I prefer this one:
<code><pre>
newcommand{\lstJava}[1]{%
\lstinline[language=Java,breaklines=true,mathescape,%
literate={\-}{}{0\discretionary{-}{}{}}]§#1§}
</pre></code>
As '§' is rarely used in Java, I use this character as code delimiter in <code>lstinline</code>. Also, '$' is seldom found in Java code, so I activate mathescape by default as I use it from time to time (that is, more often then '$' in Java). Now, the trick is the <code>literate</code> option. It is used to replace a string in the code with another given string. So, the well known <code>\-</code> - command (telling LaTeX where to hyphenate a word) is replaced here! And it is replaced by the <code>\discretionary</code> command. This one tells LaTeX, how to hyphenate a word, which is especially useful in German writings, where "ck" becomes "k-k". We use this command here to output the hyphen only when necessary.
With this command, hyphenation is working within lstinline -- however you will have to mark it manually.
<code><pre>
Let's have a look at a rather long Java class, called \lstJava{ThisIsA\-VeryLong\-ClassName}.
</pre></code>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com1tag:blogger.com,1999:blog-1765650071152206388.post-41687849807653785842010-04-18T12:34:00.003+01:002010-04-18T12:46:18.045+01:00Create BibTeX Entry from Safari Document with BibDeskI often have to reference webpages from my papers. I use bibtex and in order to reference a webpage I define a new bibtex entry of type webpage. Since I do not want to type in these entries manually, and thanks to BibDesk, a small applescript does the trick for me:
<div style="width:97%; height:200px; overflow:auto;"><code><pre>
-- (C) 2010 Jens von Pilgrim
tell application "Safari"
set theTitle to name of front document
set theURL to URL of front document
end tell
set theDate to (year of (current date)) & "-"
set theMonth to (month of (current date)) * 1
if theMonth < 10 then
set theDate to theDate & "0"
end if
set theDate to theDate & theMonth & "-"
set theDay to day of (current date)
if theDay < 10 then
set theDate to theDate & "0"
end if
set theDate to (theDate & theDay) as text
display dialog "Key for webpage " & theTitle & ": " default answer ""
set dlgResult to result
if (button returned of dlgResult = "OK") then
set theKey to text returned of dlgResult
tell application "BibDesk"
if (count of documents) = 0 then make new document
tell document 1
set newPub to make new publication at end of publications
set type of newPub to "webpage"
set cite key of newPub to theKey
set the value of field "Key" of newPub to theKey
set the value of field "Type" of newPub to "URL"
set the value of field "Url" of newPub to theURL
set the value of field "Lastchecked" of newPub to theDate
set the value of field "Title" of newPub to "{" & theTitle & ", Project Website}"
show newPub
end tell
end tell
end if
</pre></code></div>
This script grabs the URL from the currently active Safari document and creates a new bibtex entry. Some field are automatically filled, including "Type" which is required by some styles I use.The script asks for the key of the new entry, as this cannot be determined automatically (at least, I don't want the script to make a false guess). I added the script to the BibDesk script folder (at ~/Library/Application Support/BibDesk/Scripts), so it is accessible from within BibDesk.
Example: The script produces for <a href="http://bibdesk.sourceforge.net/">http://bibdesk.sourceforge.net/</a> the following entry:
<pre>
@webpage{BibDesk,
Date-Added = {2010-04-18 13:40:38 +0200},
Date-Modified = {2010-04-18 13:40:38 +0200},
Key = {BibDesk},
Lastchecked = {2010-04-18},
Title = {{BibDesk, Project Website}},
Type = {URL},
Url = {http://bibdesk.sourceforge.net/}}
</pre>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com2tag:blogger.com,1999:blog-1765650071152206388.post-82394067640222414142010-04-18T11:55:00.006+01:002010-04-18T17:58:58.325+01:00Convert Text to a (TeXShop) Convenient Label<a href="http://texshop.org/">TeXShop</a> support smart selection of words. If you double-click a text, the whole word is selected. A word in TeXShop consists of the letters 'A/a' to 'Z/z' and underscores. Spaces and hyphen '-' are not interpreted as word but as whitespaces separating words. With <a href="http://bibdesk.sourceforge.net/">BibDesk</a> installed <a href="http://www.blogger.com/post-edit.g?blogID=1765650071152206388&postID=8239406764022241414#mark1"><sup>1)</sup></a>, you can press the F5 key within a <span class="Apple-style-span" style="font-family:'courier new';">\ref</span>-command and a list will pop up with all the labels defined in your text.<div>
</div><div>If you want to quickly select a label in order to copy and paste it manually to a reference (e.g., if you do not use \ref but \autoref instead, the latter is not recognized as reference command by BibDesk), spaces and hyphens (and other punctuation characters) are really annoying as you cannot simply select the label using a double click. Even more annoying: If a label is selected from the proposal list (activiated via F5), only the label characters before the first space or punctuation character are pasted.</div><div>
</div><div>For that reason I do not use whitespaces or punctuation characters in labels. Since I do not want to convert all characters myself, I have added a new macro to TeXShop (with a nice shortkey on Cmd+'_') which does the trick:</div>
<div>
<code><pre>
--Applescript direct
-- Converts spaces and punctuation characters to underscores, useable for labels
-- (C) 2010 Jens von Pilgrim
tell application "TeXShop"
set snippet to the content of the selection of the front document
-- replace commands
set snippet to do shell script ¬
"echo " & the quoted form of snippet & ¬
" | sed -E 's/([[:space:]]|[[:punct:]])/_/g'"
set the selection of the front document to snippet
end tell
</pre></code></div><div>Note: In a <a href="http://jevopi.blogspot.com/2010/03/create-section-headers-with-texshop-and.html">previous posting</a>, I published a macro creating section headers automatically. I have improved this macro in order to convert the whitespaces and punctuation characters in labels as well.</div>
<div><a name="mark1"><sup><span class="Apple-style-span" style="font-size:x-small;">1)</span></sup></a><span class="Apple-style-span" style="font-size:x-small;">Thank you, Herb Schulz, for <a href="http://www.apfelwiki.de/forum/viewtopic.php?f=6&t=2110&sid=ed88140c5d928ba2fc373d0713f51730">reminding me</a> that it's BibDesk which adds the completion list to TeXShop ;-)</span></div>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-68429128650707599962010-04-06T16:13:00.009+01:002010-06-15T16:42:09.642+01:00BBL to BIB with BibDesk<a href="http://bibdesk.sourceforge.net/">BibDesk</a> manages my bibliography, just like iTunes manages my music. I have a single iTunes library, and I also have only a single master bibliography.
However, when writing a paper, I want to create a new bib file with only the publications cited in the paper. BibTeX nicely creates a bibliographic reference file (*.bbl), but I want a bibliography file (*.bib) in order to be able to open the paper related publications with BibDesk. So, what I needed was a tool to convert the bbl file into a bib file. Fortunately, I found everything for that on my machine: AppleScript, grep, sed and, of course, BibDesk.
I wrote a small script which simply creates a new bib file using a source bib file and a selected bbl file. Simply install the script listed below to your script folder (<code>~/Library/Scripts</code>) and name it "Create BIB from BBL.scpt" . Open your master bib file with BibDesk, then select a bbl file and activate the script(from the script menu in the menu bar). It will automatically create a new bib file in the folder of the bbl file, with the same name as the original bbl file (but with the extension bib).
<pre style="margin:0px; padding:6px; border:1px inset; width:640px; height:300px; overflow:auto"><div dir="ltr" style="text-align:left;">
-- Creates a new bib-file from an bbl-file using BibDesk
-- (C) 2010 Jens von Pilgrim
-- Version: 1.1, 20100615
tell application "Finder"
set selectedItems to the selection
end tell
if ((count of selectedItems) = 0) then
display dialog "Please select at least one bbl file" buttons {"OK"}
return
end if
-- retrieve master bib file
set sourceDoc to ""
tell application "BibDesk"
if (count of documents) = 0 then
display dialog "Please open the source bibliography with BibDesk" buttons {"OK"}
return
end if
if (count of documents) > 1 then
set listOfNames to {} as list
repeat with doc in documents
set listOfNames to listOfNames & name of doc
end repeat
set selected to (choose from list listOfNames) as string
repeat with i from 1 to the count of documents
set doc to (item i of documents)
set strDocName to name of doc as string
if (strDocName is equal to selected) then
set sourceDoc to document i
log "source doc set"
end if
end repeat
if sourceDoc is equal to "" then
return
end if
else
set sourceDoc to document 1
end if
end tell
-- log "copy items from master bib file"
-- convert all selected bbl files
repeat with theItem in selectedItems
set theFile to theItem as alias
set posixpath to POSIX path of theFile
if (offset of ".bbl" in posixpath) > 0 then
set destPosixpath to (my rename(posixpath, "bbl", "bib"))
set destFile to POSIX file destPosixpath
tell application "Finder"
if (exists destFile) then
set rep to display dialog "File " & destFile & " already exists. Overwrite?" buttons {"Yes", "No"}
set skip to (button returned of rep = "No")
else
set skip to false
end if
end tell
if (not skip) then
-- log "examine bbl file " & quoted form of posixpath
-- actually, this is the most important line:
set allCites to do shell script "grep -E \"\\\\\\\\bibitem[:space:]*(\\[[^]]*\\])?[:space:]*{([^}]*)}\" " & (quoted form of posixpath) & " | sed -E \"s/\\\\\\\\bibitem[:space:]*(\\[[^]]*\\])?[:space:]*{([^}]*)}/\\2/\""
set numberOfItems to length of paragraphs of allCites
if numberOfItems = 0 then
display dialog "No bibitems found in " & posixpath & ", maybe the file does not contain any bibitems or the search pattern does not recognize your file format." buttons {"Too bad."}
else
set numberOfMissedItems to 0
set missedItems to ""
tell application "BibDesk"
set destDoc to make new document
repeat with cite in paragraphs of allCites
set bibs to search sourceDoc for cite
set bFound to false
repeat with bib in bibs
set strFoundKey to cite key of bib as string
set strCite to cite as string
if strFoundKey is equal to strCite then
-- log strCite & " found, add to new bib"
set newBib to make new publication at end of publications of destDoc
duplicate bib to newBib
set bFound to true
end if
end repeat
if not bFound then
set numberOfMissedItems to numberOfMissedItems + 1
if (numberOfMissedItems > 1) then
set missedItems to missedItems & ", "
end if
set missedItems to missedItems & cite
end if
end repeat
save destDoc in destFile
end tell
if numberOfMissedItems > 0 then
display dialog "Did not found " & numberOfMissedItems & " out of " & numberOfItems & " items: " & missedItems & "." buttons {"Uups"}
end if
end if
end if
else
display dialog "Can only extract bib entries from BBL file, was " & posixpath
end if
end repeat
-- this sub-routine just comes up with the new name
on rename(item_name, item_ext, new_extension)
set the trimmed_name to text 1 thru -((length of item_ext) + 2) of the item_name
set target_name to (the trimmed_name & "." & new_extension) as string
return the target_name
end rename
</div></pre>
If you don't have BibDesk, you might want to have a look at <a href="http://blog.mikezhang.com/2007/07/04/bibtex-entry-extractorsubsetter">Michael Zhang's Perl Script</a>. Instead of parsing the bbl file, Zhang's script parses the latex source. I prefer parsing the bbl file, as sometimes I use a whole bunch of latex sources, and BibTeX is quite good in gathering all citations into a single bbl file. You may also want to read the comments to Zhang's post for other solutions. If you don't have a master bib file, you may look at <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=makebib">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=makebib</a>. There's a perl scrip provided reconstructing a bib file from a bbl file only.
<i>Update 2010-06-15:</i> I updated the script as some BBL files were not recognized. If the script doesn't work, you may have a look at your BBL file. At the moment, the script searches for bibitems like "\bibitem{key}" or "\bibitem[abbr]{key}".Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com8tag:blogger.com,1999:blog-1765650071152206388.post-56346142136277503692010-03-23T12:58:00.008+01:002010-03-23T13:40:46.567+01:00Nicely formatted listings in LaTeX with adjusted fontsI'm using the <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/listings/">listings package</a> in order to get nicely formatted listings in latex. Since many people are used to the fonts and syntax highlighting of their IDE, I tried to emulate the layout and colors of code as it is formatted in <a href="http://eclipse.org">Eclipse</a>. Thanks to XeTeX, I'm able to simply change the font in listing as well. I use two fonts for listing paragraphs and inline:
<pre><code>
\newfontfamily\listingsfont[Scale=0.7]{Courier}
\newfontfamily\listingsfontinline[Scale=0.8]{Courier New}
</code></pre>
This enables bold fonts in typewriter, another way of solving this problem is to use LuxiMono, but I haven't tried that one.
Then I define the colors Eclipse uses, comments are defined a little bit darker:
<pre><code>
\usepackage{color}
\definecolor{sh_comment}{rgb}{0.12, 0.38, 0.18 } %adjusted, in Eclipse: {0.25, 0.42, 0.30 } = #3F6A4D
\definecolor{sh_keyword}{rgb}{0.37, 0.08, 0.25} % #5F1441
\definecolor{sh_string}{rgb}{0.06, 0.10, 0.98} % #101AF9
</code></pre>
Sometimes I need math text in listings, e.g. when writing pseudo code. Since I scaled the fonts down, the normal math fonts (displaystyle) are a little bit too large. One possible solution of resizing the math fonts would be to use <code>\DeclareMathSizes</code>, however I do not want to change the font for the whole document. The listings package provides two properties "escapebegin" and "escapeend", which are inserted before and after escaping to latex or math. However, simply using </code>escapebegin={\ \scriptstyle}</code> would cause errors when escaping not to math but to normal latex mode. In order to solve that problem, I define a custom command:
<pre><code>
\def\lstsmallmath{\leavevmode\ifmmode \scriptstyle \else \fi}
\def\lstsmallmathend{\leavevmode\ifmmode \else \fi}
</code></pre>
Now I'm ready to define the overall style for listings:
<pre><code>
\lstset {
frame=shadowbox,
rulesepcolor=\color{black},
showspaces=false,showtabs=false,tabsize=2,
numberstyle=\tiny,numbers=left,
basicstyle= \listingsfont,
stringstyle=\color{sh_string},
keywordstyle = \color{sh_keyword}\bfseries,
commentstyle=\color{sh_comment}\itshape,
captionpos=b,
xleftmargin=0.7cm, xrightmargin=0.5cm,
lineskip=-0.3em,
escapebegin={\lstsmallmath}, escapeend={\lstsmallmathend}
}
</code></pre>
Comments are printed italic for black-white prints. In order to simplify the use of <code>\lstinline</code>, I define some commands for my favorite languages, e.g.,
<pre><code>
\newcommand{\lstJava}[1]{\lstinline[language=Java,breaklines=true,basicstyle= \listingsfontinline]$#1$}
</code></pre>
<h4>Example</h4>
<pre><code>
%:lst:Test
\begin{lstlisting}[language=Java, caption={Just a test}, label={lst:Test}]
package de.jevopi;
/*
* This is my class
*/
public class Test {
public void foo(String s) {
System.out.println("Hello " + s);
}
}
\end{lstlisting}
</code></pre>
will produce the following output (on the left). On the right, you can see the Eclipse version of the very same code snippet.
(Click to enlarge images)
<table border="0" width="90%"><tr>
<td>
<a href="http://3.bp.blogspot.com/_xki1C_H6jyM/S6izzTtH-SI/AAAAAAAAAGM/Wj0tXYZSAJg/s1600-h/listings_foo.png"><img style="display:block; margin:0px auto 10px; text-align:center;width: 320px; height: 126px;" src="http://3.bp.blogspot.com/_xki1C_H6jyM/S6izzTtH-SI/AAAAAAAAAGM/Wj0tXYZSAJg/s320/listings_foo.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5451805042976225570" /></a>
</td>
<td><a href="http://1.bp.blogspot.com/_xki1C_H6jyM/S6izzmqsbLI/AAAAAAAAAGU/zh-eSOr9_cg/s1600-h/Eclipse_foo.png"><img style="display:block; margin:0px auto 10px; text-align:center;width: 320px; height: 193px;" src="http://1.bp.blogspot.com/_xki1C_H6jyM/S6izzmqsbLI/AAAAAAAAAGU/zh-eSOr9_cg/s320/Eclipse_foo.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5451805048066305202" /></a>
</td>
<tr></table>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com3tag:blogger.com,1999:blog-1765650071152206388.post-38668483092373529342010-03-04T11:12:00.008+01:002010-03-04T13:53:59.932+01:00Spell Checker, LaTeX, and OS X<p>Spell checking is a standard feature today. With LaTeX however it is not too easy to achieve. You can certainly use the build-in spell checker of OS X, but then you have to "proof read" all LaTeX commands and their parameters, which can be annoying. So I was looking for a better solution.</p>
<p>Because it was automatically installed I tried <a href="http://excalibur.sourceforge.net/">Excalibur</a>. Frankly, I don't like it at all, but maybe I have missed something. It only offers very limited options. Unfortunately it doesn't support UTF-8. Since I'm using XeTeX wiht UTF-8, a spell checker w/o UTF-8 support is useless for me.</p>
<p>So I tried Aspell. If you look at the <a href="http://aspell.net/">Aspell webpage</a>, you'll get this "Linux users have to compile their application" feeling. There is a <a href="http://aspell.darwinports.com/">darwin port of aspell</a> triggering a "Darwin users have to compile their application" feeling... </p>
<p>Fortunately, I eventually found <a href="http://cocoaspell.leuski.net/">CocoAspell</a>. (Yes, well, there's a link to it on the TeXShop website ;-) ...) It comes with an installer, so you don't have to install XCode or Fink :-D. Best of all, it installs a system preference panel -- and that's really great!
<a href="http://1.bp.blogspot.com/_xki1C_H6jyM/S4-LZcca9NI/AAAAAAAAAF0/_bl7x_i0lQg/s1600-h/cocoAspell_preference_panel.png"><img style="display:block; margin:0px auto 10px; text-align:center;width: 320px; height: 271px;" src="http://1.bp.blogspot.com/_xki1C_H6jyM/S4-LZcca9NI/AAAAAAAAAF0/_bl7x_i0lQg/s320/cocoAspell_preference_panel.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5444723743762609362" /></a>
With this filter shown in the screenshot you can define LaTeX commands and if their arguments are to be spell checked. For example, the argument of \section{} is to be spell checked, while labels (\label{} ) are not to be spell checked. It comes with a list of predefined commands, and I added some commands, e.g., \autoref{} (as you can see in the screenshot).
<p>You can find dictionaries at <a href="ftp://ftp.gnu.org/gnu/aspell/dict">ftp://ftp.gnu.org/gnu/aspell/dict</a>, before downloading them read <a href="http://people.ict.usc.edu/~leuski/cocoaspell/install_dict.html">the hints at cocoAspell's webpage</a>.</p>
<p>I had some problems activating the Aspell dictionaries in <a href="http://www.uoregon.edu/~koch/texshop/texshop.html">TeXShop</a>. Of course, you have to activate the dictionary in cocoAspell's prefernce panel. And I had to deactivate the "check spelling" box in the TeXShop preference, I don't know why. Spell checking is activated in TeXShops edit menu, I don't know what this preference setting is good for...</p>
<p>Well, spell checking a document for the first time usually means to add a lot of word to the dictionary. Sometimes, you want to edit this user dictionary (maybe because you added a word by mistake of because you want to add an existing list). The user dictionaries can be found at <code>~/Library/Spelling</code>. These files are simple text files and you can open and edit these files with almost any editor. However, the words are separated with an usually invisible character, so you have to use an editor which can show invisible characters, such as <a href="http://www.subethaedit.net/">SubEthaEdit</a> (unfortunately, TeXShop cannot show these characters).</p>
<p>OK, now that we have a nice spell checker for LaTeX, we only have to change the language in "Spelling and Grammar". However, opening that tiny window requires a bunch of mouse clicks, and often we do not want to actually spell check but only change the dictionary. I found a small applescript at <a ref="http://forums.macosxhints.com/showthread.php?t=26835">maxoxhints forum</a>, and the version provided by Eponymous works for me. Eponymous' script could be added to the apple script menu and then will be available in all applications. Note: In order to make this script work, you have to activate
"Enable access for assistive devices" in the "Universal Access" panel of the system preferences.</p>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com1tag:blogger.com,1999:blog-1765650071152206388.post-7158312114566451502010-03-02T11:45:00.006+01:002010-04-18T12:23:22.719+01:00Create Section Headers with TexShop and ApplescriptI really like the macro feature of <a href="http://texshop.org">TexShop</a>. One of the most common use cases of macros would probably be the definition of a section (or subsection etc.). My section-creation-macro has been quite simple in the past:
<pre><code>
% ----------------------------------------
% \section{#SEL##INS#}
% \label{sec:#SEL#}
% ----------------------------------------
</code></pre>
This small snippet creates a nicely formatted section header including a label. However, there's a really annoying problem: When creating a reference to a section (that is, to its label), TeXShop does not handle spaces accordingly when selecting a label from the dropdown list. For example, if your label is something like \label{sec:Hello World}, the complete label is shown in the list, but only \ref{sec:Hello} is inserted into the text. In order to overcome this problem, I always replace spaces in labels with underscores. So my label would be "sec:Hello_World", and TeXShop is working perfectly.
But replacing spaces with underscores by hand is even more annoying. So I replaced my section macro with an applescript version:
<div style="width:97%; height:200px; overflow:auto;"><pre><code>
--Applescript direct
-- Create a section header from selected text. A label is automatically added with a prefix
-- "sec:", spaces are converted to underscores.
-- (C) 2010 Jens von Pilgrim
property level : "section"
property cmtchar : "-"
property cmtlength : 78
property labelprefix : "sec:"
-- property newline: "\n"
tell application "TeXShop"
tell application "TeXShop" to set title to the content of the selection of the front document
set new_title to title
if ((count of the paragraphs of title) ≥ 1) then
set this_line to paragraph 1 of title
set label to this_line
set add to "true"
-- replace commands
set label to do shell script ¬
"echo " & the quoted form of label & ¬
" | sed -E 's/([[:space:]]|[[:punct:]])/_/g'"
set comment to "% "
repeat with ii from 1 to cmtlength
set comment to comment & cmtchar
end repeat
set new_title to ¬
comment & return & ¬
"\\" & level & "{" & title & "}" & return & ¬
"\\label{" & labelprefix & label & "}" & return & ¬
comment & return
end if
tell application "TeXShop" to set the selection of the front document to new_title
end tell
</code></pre></div>
This macro creates a section just like the initial macro version, but this time spaces are automatically replaced in the label. That is, simply select your section title, activate the macro, and you get a nicley formatted title with a TeXShop compatible label. E.g.
Mark
<pre>
Hello World, this is great
</pre>
and the macro will convert this to
<pre>
% ==============================================================================
\section{Hello World, this is great}
\label{sec:Hello_World__this_is_great}
% ==============================================================================
</pre>
You can easily adjust the macro in order to create subsection, subsubsections or chapters as well. I have different kind of comments for different section levels, all you have to change are the properties in the first line:
<pre><code>
...
property level : "section"
property cmtchar : "-"
property cmtlength : 78
property labelprefix : "sec:"
...
</code></pre>
Change level to "subsection" or whatever, and set the cmtchar to "*", "." or whatever you like.
Changing a section level has already been subject of another blog post: <a href="http://jevopi.blogspot.com/2009/07/increasedecrease-section-level-with.html">Increase/Decrease Section Level with TeXShop Macros</a>.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-6752763156150625242010-01-29T16:52:00.006+01:002010-02-07T15:42:18.349+01:00OmniGraffle and multi-language diagramsSometimes I need diagrams in different languages for different purposes. E.g., for presentations on international conferences, I use english labels, while I need german labels for my thesis (which is written in German). I sometimes change my diagrams, I don't want to have two version of a diagram, one in english, another one in german. Because I always export my diagrams to PDF, I'm using two smart export scripts in conjunction with layers, used for internationalization (i18n).
First of all, I add a layer for each language. In order to distinguish these internationalization layers from other layers, I use a prefix "lang_". All language specific labels and elements are added to that layer. Other things are placed on layers without my language prefix. Usually, I initially create the diagram in one language, and then move all language specific stuff to the language layer. I then copy all that language specific stuff and paste it onto another language layer (or, simply duplicate the layer), where it is translated. By changing the visibility of the language layers, I can change the language of the diagram. Since it is one diagram, changes on the shared layer are reflected in all language versions, language dependant things have to be adjusted (and translated) manually. The following screenshots show a sample diagram with three layers for shared, english and german elements.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MIPdb0PGI/AAAAAAAAAFc/jd-z2XC6gas/s1600-h/i18n+layers.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 222px;" src="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MIPdb0PGI/AAAAAAAAAFc/jd-z2XC6gas/s320/i18n+layers.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5432194637231307874" /></a>
In order to create language specific PDFs, I have modified a script I published <a href="http://jevopi.blogspot.com/2007/02/applescript-convert-omnigraffle.html">here</a> some time ago. Here is the modified version:
<pre style="margin:0px; padding:6px; border:1px inset; width:640px; height:300px; overflow:auto"><div dir="ltr" style="text-align:left;">-- converts selected OmniGraffle files to PDF with internationalization
-- based on Greg Titus's script found at
-- http://forums.omnigroup.com/showthread.php?t=106&highlight=export+applescript
--
-- by jevopi, 2010
global export_language, layer_prefix
set export_language to "de"
set layer_prefix to "lang_"
tell application "Finder"
set these_items to the selection
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items) as alias
set this_info to info for this_item
-- insert actions here for: this_item
set item_path to POSIX path of this_item
set item_folder to (parent of (item i of these_items)) as string
set item_name to name of (item i of these_items)
set item_ext to name extension of (item i of these_items)
set exp_name to my rename(item_name, item_ext, "pdf")
set exp_path to item_folder & exp_name
set msg to "Path: " & item_path & ", Exp: " & exp_path
--display dialog msg buttons {"OK"} default button 1
my omniConvert(this_item, item_path, exp_path)
end repeat
-- this sub-routine just comes up with the new name
on rename(item_name, item_ext, new_extension)
tell application "Finder"
if the item_ext is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of item_ext) + 2) of the item_name
end if
set target_name to (the trimmed_name & "_" & export_language & "." & new_extension) as string
end tell
return the target_name
end rename
-- this sub-routine does the export
on omniConvert(source_file, source_path, target_path)
with timeout of 900 seconds
tell application "OmniGraffle Professional 5"
-- save the current export settings so we can replace them later
set oldAreaType to area type of current export settings
set oldBorder to include border of current export settings
set oldBackground to draws background of current export settings
-- here is where you set the export settings you want
set area type of current export settings to all graphics
set include border of current export settings to false
set draws background of current export settings to false
set export scale of current export settings to 1
set border amount of current export settings to 0
-- open the file if it isn't already open
set needToOpen to (count (documents whose path is source_path)) is 0
if needToOpen then
open source_file
end if
-- do the export
set docsWithPath to documents whose path is source_path
set theDoc to first item of docsWithPath
set allLayers to layers of first canvas of the theDoc
repeat with i from 1 to the count of allLayers
set theLayer to (item i of allLayers)
-- repeat with theLayer in layers of first canvas of theDoc
set theName to name of theLayer
if (offset of layer_prefix in theName) > 0 then
if theName = layer_prefix & export_language then
set visible of theLayer to true
else
set visible of theLayer to false
end if
end if
end repeat
save theDoc in file target_path
-- if the file wasn't already open, close it again
if needToOpen then
close theDoc saving no
end if
-- put the original export settings back
set area type of current export settings to oldAreaType
set include border of current export settings to oldBorder
set draws background of current export settings to oldBackground
end tell
end timeout
end omniConvert
</div></pre>
This script exports an OmniGraffle diagram to PDF. Besides, only one language specific layer is made visible and the langauge id is added to the filename. The language is defined in line
<pre>
set export_language to "de"
</pre>
That is, this script automatically creates a german version of the diagram. I have a script for each language (and one w/o i18n) in my script folder, e.g.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MLKh4LaiI/AAAAAAAAAFk/1VoyfM_yMZQ/s1600-h/scripts.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 69px;" src="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MLKh4LaiI/AAAAAAAAAFk/1VoyfM_yMZQ/s320/scripts.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5432197851059546658" /></a>
After applying the both i18n-scripts to the diagram, two PDFs are created from my diagram:
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MLK18GyII/AAAAAAAAAFs/xd7sf1LLyS4/s1600-h/files.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 166px;" src="http://3.bp.blogspot.com/_xki1C_H6jyM/S2MLK18GyII/AAAAAAAAAFs/xd7sf1LLyS4/s320/files.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5432197856444729474" /></a>
This technique works pretty well with text and connection labels. Unfortunately labels placed on shapes cannot be moved on a layer different from the shape. So, in these cases you have to move the whole shape to the language layer. If you translate a diagram after you have created it, this works pretty well. It may become a little bit annoying if you have to change the diagram, but at least you are aware of the changes and don't have to work with two separate files.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-87943871887053956562009-09-20T13:40:00.005+01:002012-05-21T14:29:04.162+01:00Acronyms and LaTeXComputer geeks like acronyms, especially three-letter acronyms (TLAs). To give you an impression: I'm working in the area of MDD. Actually, OMG calls it MDA, Stuart Kent MDE, and others MDSD. In short, models, such as UML or EMF models, are transformed into other models or code by M2M- or M2T-transformations, such as QVT or ATL.
Writing a thesis in that area is really hard, since you have to keep an eye on all that TLAs. So I've looked for a LaTeX package doing the job for me, and what I found is a package called <em>acronym</em> by Tobias Oetiker. I really like the simplicity of this package, this is why I decided to use that instead of other alternative solutions.
<h4>Install acronym</h4>
Surprisingly, it was already installed with my tex installation (gwTeX), but it requires a packages called <em>suffix</em>, which was not. The later is contained in a bundle called <em>bigfoot</em>.
Here are the CTAN locations of acronym and bigfoot:
<ul>
<li><a href="http://tug.ctan.org/tex-archive/macros/latex/contrib/acronym/">http://tug.ctan.org/tex-archive/macros/latex/contrib/acronym/</a></li>
<li><a href="http://tug.ctan.org/tex-archive/macros/latex/contrib/bigfoot/">http://tug.ctan.org/tex-archive/macros/latex/contrib/bigfoot/</a></li>
</ul>
In order to install a package from the files available at CTAN, you usually have to
<ul>
<li>download the zip or all the files from CTAN</li>
<li>unzip them (or put them into a folder) and put the folder somewhere tex can find it, e.g. into <code>$HOMETEXMF</code> (i.e. <code>~/library/texmf/tex</code>)</li>
<li>run the installer via <code>latex *.ins</code>, in that case <code>latex bigfoot.tex</code></li>
</ul>
Now you are ready to use <em>acronym</em>. It is quite simple: simply include the package via
<pre><code>\usepackage{acronym}</code></pre>
Instead of simply writing the acronym in your text, you now have to write <code>\ac{..}</code> (or, in case of a plural, <code>\acp{..}</code>). You have to add a new environment with a list of all the acronyms and their long form with
<pre><code>
\begin{acronym}
\arcro{..}{...}
\end{acronym}
</code></pre>
The first time an acronym is used, <code>\ac</code> prints the long form with the acronym in brakets.
There are also some other commands available, see the <em>acronym</em> documentation for details.
<h4>Add list of acronyms to table of contents</h4>
Unfortunately, there is no command available for adding an entry to the table of contents. I have written my own command for that, which creates an entry similar to the list of figures. You have to add the following code somewhere in your preamble:
<pre><code>
\@ifundefined{listofacronymsname}{\newcommand{\listofacronymsname}{Acronyms}}{}
\@ifundefined{chapter}{%
\newcommand{\listofacronyms}{%
\section*{\listofacronymsname}%
\addcontentsline{toc}{section}{\listofacronymsname}%
\label{sec:acronyms}%
\markboth{\listofacronymsname}{\listofacronymsname}%
}}{%
\newcommand{\listofacronyms}{%
\chapter*{\listofacronymsname}%
\addcontentsline{toc}{chapter}{\listofacronymsname}%
\label{sec:acronyms}%
\markboth{\listofacronymsname}{\listofacronymsname}%
}}
</code></pre>
It defines two commands:
<dl>
<dt><code>\listofacronymsname</code></dt><dd>defines the name of the heading used for the list of acronyms. It is "Acronyms" by default, but you can change that with <code>\renewcommand</code>, as demonstrated below.</dd>
<dt><code>\listofacronyms</code></dt><dd> creates a heading and a section or chapter definition (depending on the document class), which is also added to the table of contents. A label "sec:acronyms" is added as well.</dd>
</dl>
(Update 2012-05-21: <code>\markboth</code> adjusts the header accordingly, see <a href="http://www.mrunix.de/forums/showthread.php?t=44175">mrunix thread</a>)
<h4>Put it all together</h4>
Let's put it all together. Firstly, we use the package and define the <code>\listofacronyms</code> command:
<pre><code>
\usepackage[printonlyused,smaller]{acronym} % acronyms ac
\@ifundefined{listofacronymsname}{\newcommand{\listofacronymsname}{Acronyms}}{}
...
</code></pre>
I have added some parameters to only list the used acronyms and use a slightly smaller font.
Secondly, we create a new file "<code>acronyms.text</code>" with a list of the acronyms, which makes it easier to maintain. This is how my file looks like:
<pre><code>
\renewcommand{\listofacronymsname}{Abkürzungsverzeichnis} % german title
\listofacronyms
% \acro{acronym}[shortname]{fullname}
% inside fullname: \acroextra{} -- not in text, only in description list
\begin{acronym}
\acro{EMF}{Eclipse Modeling Framework \cite{EMF}}
\acro{GEF}{Graphical Editing Framework \cite{GEF}}
\acro{MDD}{Model Driven Development}
\acro{MDA}{Model Driven Architecture}
\acro{UML}{Unified Modeling Language}
...
\end{acronym}
</code></pre>
The acronyms are not sorted automatically, I use SubEthaEdit for sorting the acronyms from time to time, but I guess there are several editors which can do that.
This file has to be included in your main latex source document, e.g.,
<pre><code>
\begin{appendix}
\input{acronyms}
\end{appendix}
</code></pre>
Last but not least, we have to use the <em>acronym</em> commands in the text, just like that:
<pre><code>
I'm working in the area of \ac{MDD}. Actually, \ac{OMG} calls it \ac{MDA}, Stuart Kent \ac{MDE}. In short, models, such as \ac{UML} or \ac{EMF} models, ...
</code></pre>
You do not have to look for the first usage of an acronym anymore, <em>acronym</em> is doing that for you. If you forget to define an acronym, you will see that in the generated output as <em>acronym</em> creates a bold placeholder in that case. If you do not want to printed the list of acronyms, you can use <em>acronym</em> just as described before, you only have to add a package option <code>nolist</code> (i.e. <code>\usepackage[nolist]{acronym}</code>). This is especially useful in combination with the option <code>footnote</code>, as in that case the description of the acronym is printed as a footnote and not in the text (and one can find the definitions by scanning the footnotes, which is ok for shorter texts).
Thank you very much, Tobias Oetiker, for writing that package!Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-87304085169702707952009-07-22T17:48:00.006+01:002010-01-29T16:25:09.466+01:00OmniGraffle StencilsMy favorite application for creating nice drawing is <a href="http://www.omnigroup.com/applications/OmniGraffle/">OmniGraffle</a>. At <a href="http://www.graffletopia.com/">Graffletopia</a> you can find lots of user created stencils, that is templates for using in your own drawing. The latest version of OmniGraffle let you search a stencil directly at Graffletopia, so if you think you need something like UML notation elements, just enter UML in OmniGraffel's stencil window and you will find several stencils at Graffletopia.
I have created some stencils as well, and you can download them from Graffletopia. You can either search for them from within OmniGraffle, or you can download and install them manually. Here is a list of my stencils:<div><ul><li><a href="http://www.graffletopia.com/stencils/447">UML 2.1 Collection</a>: A collection of notation elements for creating UML 2 class, activity, use case, sequence, or component diagrams. It's a rather large stencil, but it contains most UML 2.1 elements</li><li><a href="http://www.graffletopia.com/stencils/448">Feature Diagrams</a>: Feature Diagram stencil, notation based on the book "Generative Programming" by K. Czarnecki and U.W. Eisenecker. (Updated today and fixed some problems)</li><li><a href="http://www.graffletopia.com/stencils/487">Post-it Notes</a>: A collection of six colored post-it notes with nice shadow, slightly bended.</li></ul>Have fun!</div>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-64133315078286777802009-07-16T14:05:00.005+01:002009-07-16T14:24:38.936+01:00Increase/Decrease Section Level with TeXShop MacrosTeXShop is a really nice editor, especially since new commands can be added using macros. These macros can contain AppleScript, which makes them very flexible and powerful.
I like formating my headings in order to easily see sections, subsections etc. For that reason, I have added some macros creating sections etc. like this:
Macro "section":<pre><code>
% ==============================================================================
\section{#SEL##INS#}
\label{sec:#SEL#}
% ==============================================================================
</code></pre>
My latex code then looks like that:<div style="width:97%; height:200px; overflow:auto;"><pre><code>
% ******************************************************************************
\chapter{Chapter}
\label{chapter:Chapter}
% ******************************************************************************
% ==============================================================================
\section{Section}
\label{sec:Section}
% ==============================================================================
% ------------------------------------------------------------------------------
\subsection{SubSection}
\label{sec:SubSection}
% ------------------------------------------------------------------------------
% ..............................................................................
\subsubsection{SubSubSection}
\label{sec:SubSubSection}
% ..............................................................................
\paragraph{Paragraph}
</code></pre></div>
This works pretty well. But it becomes very painful to change a section to a subsection, because I do not only want to change "section" to "subsection", but the comment lines as well. So I added two macros including AppleScript in order to decrease or increase the level of a section.
I assume other people might find these macros useful, so I publish them here. They are written very quick and dirty, so you may have to adapt them to suit your preferences:
Macro: "Decrease Section Level":<div style="width:97%; height:200px; overflow:auto;"><pre><code>
--Applescript direct
-- Decrease Section Level
--Select Section Block including Comments to decrease section level, i.e. section become subsection, chapter becomes section and so on
-- (C) 2009 Jens von Pilgrim
--THE SCRIPT:
property texapp : "TeXShop"
tell application texapp
if texapp = "TeXShop" then
tell application "TeXShop" to set section to the content of the selection of the front document
else if texapp = "iTeXMac" then
--tell application "iTeXMac" to set section to (the selection of the text of the front document)
end if
set new_section to ""
repeat with ii from 1 to the count of the paragraphs of section
set this_line to paragraph ii of section
set new_line to this_line
set add to "true"
-- replace commands
if this_line contains "\\chapter" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\chapter/\\\\section/'"
end if
if this_line contains "\\section" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\section/\\\\subsection/'"
end if
if this_line contains "\\subsection" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\subsection/\\\\subsubsection/'"
end if
if this_line contains "\\subsubsection" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\subsubsection/\\\\paragraph/'"
end if
-- replace the comments
if this_line contains "% ******************************************************************************" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\*/=/g'"
end if
if this_line contains "% ==============================================================================" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/=/-/g'"
end if
if this_line contains "% ------------------------------------------------------------------------------" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/-/\\./g'"
end if
if this_line contains "% .............................................................................." then
set add to "false"
end if
if add="true" then
if new_section = "" then
set new_section to new_line
else
set new_section to new_section & return & new_line
end if
end if
end repeat
if texapp = "TeXShop" then
tell application "TeXShop" to set the selection of the front document to new_section
else if texapp = "iTeXMac" then
--tell application "iTeXMac" to insert new_section in the text of the front document
end if
end tell
</code></pre></div>
Macro: "Increase Section Level":<div style="width:97%; height:200px; overflow:auto;"><pre><code>
--Applescript direct
-- Increase Section Level
--Select Section Block including Comments to decrease section level, i.e. section become subsection, chapter becomes section and so on
-- (C) 2009 Jens von Pilgrim
--THE SCRIPT:
property texapp : "TeXShop"
tell application texapp
if texapp = "TeXShop" then
tell application "TeXShop" to set section to the content of the selection of the front document
else if texapp = "iTeXMac" then
--tell application "iTeXMac" to set section to (the selection of the text of the front document)
end if
set new_section to ""
repeat with ii from 1 to the count of the paragraphs of section
set this_line to paragraph ii of section
set new_line to this_line
set add to "true"
-- replace commands
if this_line contains "\\section" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\section/\\\\chapter/'"
end if
if this_line contains "\\subsection" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\subsection/\\\\section/'"
end if
if this_line contains "\\subsubsection" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\subsubsection/\\\\subsection/'"
end if
if this_line contains "\\paragraph" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\\\paragraph/\\\\subsubsection/'"
set new_line to "% .............................................................................." & return & new_line & return & "% .............................................................................."
end if
-- replace the comments
if this_line contains "% ==============================================================================" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/=/\\*/g'"
end if
if this_line contains "% ------------------------------------------------------------------------------" then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/-/=/g'"
end if
if this_line contains "% .............................................................................." then
set new_line to do shell script ¬
"echo " & the quoted form of this_line & ¬
" | sed 's/\\./-/g'"
end if
if add="true" then
if new_section = "" then
set new_section to new_line
else
set new_section to new_section & return & new_line
end if
end if
end repeat
if texapp = "TeXShop" then
tell application "TeXShop" to set the selection of the front document to new_section
else if texapp = "iTeXMac" then
--tell application "iTeXMac" to insert new_section in the text of the front document
end if
end tell
</code></pre></div>
These two macros increase or decrease the level of a section. You have to simply select a section (or several sections), and the levels of all chapters, sections, and paragraphs are increased or decreased respectively. Besides the commands, the comments are reformatted as well.
When increasing the levels, the following modifications are made:<ol><li>section -> chapter</li><li>subsection -> section</li><li>subsubsection -> subsection</li><li>paragraph -> subsubsection</li></ol>
When decreasing the levels, the following modifications are made:<ol><li>chapter -> section</li><li>section -> subsection</li><li>subsection -> subsubsection</li><li>subsubsection -> paragraph</li></ol>
Note that chapters are not increased any further, and paragraphs are not decreased.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com2tag:blogger.com,1999:blog-1765650071152206388.post-16665240666714868092009-07-15T12:40:00.009+01:002010-08-03T14:57:46.396+01:00How to write very long documents with LaTeXI eventually started writing my thesis--with LaTeX. Since it will become a rather long document (approx. 200 pages) I decided to split the document into its chapters (and maybe into more parts). Splitting a document is very easy with latex and it typically looks like that:
<pre><code>
\documentclass{someClass}
... some definitions, use packages etc ...
\begin{document}
...
\maketitle
...
\input{abstract}
\input{introduction}
...
\input{relatedwork}
\input{conclusion}
...
\end{document}
</code></pre>
This works pretty well, and I always use this pattern for writing smaller papers. Unfortunately I found two severe problems:
<ol><li>The latex compiler is unaware of folders.</li><li>I cannot compile the parts separately, which leads to new problems</li></ol>
<h4>Chapterfolder</h4>
The first problem is further described and solved by the latex package "chapterfolder". Instead of simply including a chapter, it is included <b>and</b> the current folder is changed accordingly. The main file will now look like this:
<pre><code>
...
\begin{document}
...
\maketitle
...
\cfchapter{Introduction}{chapters/introduction}{introduction.tex}
...
\cfchapter{Conclusion}{chapters/conclusion}{conclusion.tex}
</code></pre>
In my case I can now use chapter-relative figure folders, i.e. my folder structure looks like that:
<pre><code>
/Main
- main.tex
+ chapters
+ introduction
- introduction.tex
+ fig
- figOfChapter1.png
+ conclusion
- conclusion.tex
+ fig
- figOfChapter2.png
</code></pre>
Without "chapterfolder", I had to include a figure in chapter 1 (Introduction) like this:
<pre><code>\includegraphics{chapters/introduction/fig/figOfChapter1}</code></pre>
However, I want to be able to simply include figures by specifying a relative path to the chapter document, that is
<pre><code>\includegraphics{fig/figOfChapter1}</code></pre>
In order to achieve, this, we have to rewrite the includegraphics command. We can do that in the preamble, next to the usepackage statement:
<pre><code>\usepackage{chapterfolder}
% and we re-write includegraphics
\let\includegraphicsWithoutCF\includegraphics
\renewcommand{\includegraphics}[2][]{\includegraphicsWithoutCF[#1]{\cfcurrentfolder#2}}</code></pre>
This makes life much easier, especially if figures are moved from one chapter to another (I have only to move the file of the figure and can simply copy the code). And we are also able of compiling documents separately, as explained further on!
<h4>Compile Separately and Embedded</h4>
Although I'm using a wonderful LaTeX editor (Texshop) and my computer is pretty fast, working with a split document has some tradeoffs:
<ol><li>The "goto error" function in my editor is not working with included documents, which makes bug fixing really annoying.</li><li>Compiling a (currently) 100 page long document with lots of images takes quite some time</li></ol>For that reason, I tried to figure out how to split my document and use a main file including all parts, while at the same time the parts could be compiled standalone. Here is my solution:
In the main file, I define a command for letting the included files know that they are embedded:
<pre><code>
\newcommand{\isEmbedded}{true}
</code></pre>
In my parts (chapters), I can now test whether this command is defined or not, and include a preamble if required:
<pre><code>
\ifx\isEmbedded\undefined
..
\documentclass{../../styles/myStyle}
..
other settings
...
\begin{document}
\maketitle
...
% -------+---------+---------+---------+---------+---------+---------+---------+
\else
\fi
% ******************************************************************************
Here comes the text of the chapter or part.
% ******************************************************************************
\ifx\isEmbedded\undefined
\bibliography{myBib}
...
\end{document}
\else
\fi
</code></pre>
I can now compile every chapter separately, and finding a bug is very simple thanks to Texshops "Goto Error" function -- which is now working. Without any modifications, I can also compile the whole text, i.e. my main.tex file.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com4tag:blogger.com,1999:blog-1765650071152206388.post-59055546765713341412007-11-06T15:54:00.001+01:002010-01-29T16:25:29.401+01:00Merge PDF documents with LaTeXSometimes, a single book comes in multiple PDF documents, one document for a chapter. I often want to merge these PDF document into one single document. There are several possibilites, e.g. using Adobe Acrobat. A less expensive and yet easy solution is to use LaTeX for that purpose. So I have created a simple LaTeX template in which I only have to add the names of the documents to be merged., that's it. Besides, several options are available such as scaling the documents on the fly.
The work is done by the LaTex package "pdfpages", see <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/">pdfpages at www.ctan.org</a>. The documents are included with <code>\includepdf</code>, the two lines above this command are used here for creating a table of content in the PDF.
<pre><code>
%!TEX encoding = UTF-8 Unicode
% -------+---------+---------+---------+---------+---------+---------+---------+
\documentclass{book}
% -------+---------+---------+---------+---------+---------+---------+---------+
% Used Packages
% -------+---------+---------+---------+---------+---------+---------+---------+
\usepackage[pdftex,dvips]{graphicx}
\usepackage[english]{babel}
\usepackage[
pdfhighlight=/O, colorlinks, linkcolor=black, urlcolor=black, citecolor=black,
breaklinks, bookmarksopen,bookmarksopenlevel=1,linktocpage
] {hyperref}
\usepackage{fancyhdr}
\usepackage{pdfpages} % That does the trick!
% -------+---------+---------+---------+---------+---------+---------+---------+
% Header
% -------+---------+---------+---------+---------+---------+---------+---------+
\pagestyle{headings}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
%\fancyfoot[LE,RO]{\raisebox{-25mm}{\large\textsf{\thepage}}}
%\fancyfoot[RE,LO]{\raisebox{-25mm}{Merged Document}}
%\fancyfoot[CE,CO]{\raisebox{-25mm}{}}
\renewcommand{\headrulewidth}{0mm}
\renewcommand{\footrulewidth}{0mm}
% -------+---------+---------+---------+---------+---------+---------+---------+
% Settings for including the PDF documents,
% see:
% http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf
% -------+---------+---------+---------+---------+---------+---------+---------+
\includepdfset{pages=-,nup=1x1, pagecommand={\mbox{}}}
% -------+---------+---------+---------+---------+---------+---------+---------+
% The Documents
% -------+---------+---------+---------+---------+---------+---------+---------+
\begin{document}
\phantomsection
\addcontentsline{toc}{chapter}{Chapter 1}
\includepdf{file1.pdf}
\phantomsection
\addcontentsline{toc}{chapter}{Chapter 2}
\includepdf{file2.pdf}
% ...
% -------+---------+---------+---------+---------+---------+---------+---------+
\end{document}
</code></pre>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0tag:blogger.com,1999:blog-1765650071152206388.post-34374875516893052292007-08-01T09:37:00.000+01:002007-08-01T10:03:08.104+01:00Shell Script as Startup ItemIn my office I'm working with a PC and a Mac. I have two screens (one for the PC, one for the Mac) -- but only one mouse and one keyboard. This is possible with <a href="http://synergy2.sourceforge.net/">Synergy</a>. This is a client-server tool sending mouse and keyboards events over the network. In order to make this work, I have to start a server on one machine -- I've decided to use the Mac as the server. Since I only need Synergy at work, I wanted to start the server only when I'm at work. Fortunately I've got a static IP address, so I can check with <code>ifconfig</code> and <code>grep</code> whether I'm in my office or not. This is my shell script:
<pre><code>
#!/bin/bash
if ifconfig | grep my.static.ip.address
then
/Applications/synergy-1.3.1/synergys --config /path/to/my/synergy.conf
echo At Work! Synergy started
exit
else echo Not at work!
fi
</code></pre>
I want to execute this script as a startup item. First, I simply started the script via the terminal application. But in this case the Terminal.app is started and remains open. I didn't want that. So I wrote a small AppleScript simply starting the shell script. I saved this AppleScript as an application, and now the shell script is executed as a startup but almost invisible. The problem of using a shell script as a startup item is a common one, and the solution is very simple. This is the AppleScript:
<pre><code>
do shell script "'/path/to my/shell/script.sh'"
</code></pre>
Note that there is a litte trick in this line: The path to my script contains a space. So I have to "double quote" the path with " and '.
See also: <a href="http://developer.apple.com/technotes/tn2002/tn2065.html"> Apple Developer Connection: Technical Note TN2065</a>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.comtag:blogger.com,1999:blog-1765650071152206388.post-4186160658557364722007-02-20T12:08:00.000+01:002007-02-20T12:33:22.495+01:00SMB over SSH tunnel setupSometimes I need access to a SMB server. This SMB server is hidden behind the company's firewall and the only way to get behind the firewall is a SSH server.
So you need a so called SSH tunnel to connect your machine (outside the firewall) with the SMB server (inside the firewall).
To establish the connection, you need the following information:
<ul>
<li>Name of SSH-server and an account on that server</li>
<li>Name of SMB-server and an account on that server</li>
<li>Of course, you'll need to know which folder you want to access</li>
</ul>
The following steps install a SMB connection over a SSH tunnel. I've tested these steps using Mac OS X.
<dl>
<dt>Step 1: Install SSH tunnel</dt>
<dd>The shell command is simply
<code>ssh -N -l <i>username_on_ssh_server</i> -L 139:<i>smb_server</i>:139 <i>ssh_server</i></code>
You may call this line using sudo. After starting the tunnel, it's like you have an SMB-server running on your local machine listening on port 139 (which is the SMB port).
</dd>
<dt>Step 2: Mount SMB on localhost</dt>
<dd>You can simply mount a SMB folder on your local machine by
<code>mount_smbfs -I localhost -U <i>username_win_domain</i>//<i>smb_server_name</i>/<i>remote_folder</i> <i>local_folder</i></code>
This line mounts a folder on the smb server to your local file system.
</dd>
</dl>
Example: Assume the ssh-server is "ssh.test.com", the smb-server is "smb.test.com", your user name on ssh.test.com is "jdoe" and you want to mount the remote folder "project" to your local folder "company". Your user name on smb.test.com is "JohnDoe".
<code>ssh -N -l jdoe -L 139:smb.test.com:139 ssh.test.com</code>
and (in a new terminal window)
<code>mount_smbfs -I localhost -U JohnDoe//smb/projects company</code>
Some notes on the Finder: After mounting the folder from command line, it is possible that the Finder does not recognize the mounted folder. Browser your file system with the folder to open the folder. Sometime it happes (at least on my system) that the mounted folder cannot be seen in the finder windows. Then I have to open the folder with Cmd-Shift-G. Unmounting the folder also does not work with the finder, you will have to call <code>umount company</code> in the example and restart the finder (Ctrl-Mod click on Finder icon in dock) to remove the icon of the network folder from the desktop.Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.comtag:blogger.com,1999:blog-1765650071152206388.post-2455143850183542312007-02-20T11:43:00.001+01:002010-01-29T16:24:39.054+01:00AppleScript: Convert OmniGraffle documents to PDFThe following AppleScript converts all selected OmniGraffle drawings (*.graffle) to PDF. It is based on Greg Titus's script published <a href="http://forums.omnigroup.com/showthread.php?t=106&highlight=export+applescript">here</a>. While Greg's script watches a folder, this script simply converts all selected files.
Note: There's no error handling and you may want to change the export settings. If you have <a href="http://www.stalkingwolf.net/software/cocothumbx/">CocoThumbX</a> installed, you may want to uncomment line where sub routine "createThumb" is called and change the path to CocoThumbX.
<pre style="margin:0px; padding:6px; border:1px inset; width:640px; height:300px; overflow:auto"><div dir="ltr" style="text-align:left;">-- converts selected OmniGraffle files to PDF
-- based on Greg Titus's script found at
-- http://forums.omnigroup.com/showthread.php?t=106&highlight=export+applescript
--
-- by jevopi, 2007
tell application "Finder"
set these_items to the selection
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items) as alias
set this_info to info for this_item
-- insert actions here for: this_item
set item_path to POSIX path of this_item
set item_folder to (parent of (item i of these_items)) as string
set item_name to name of (item i of these_items)
set item_ext to name extension of (item i of these_items)
set exp_name to my rename(item_name, item_ext, "pdf")
set exp_path to item_folder & exp_name
set msg to "Path: " & item_path & ", Exp: " & exp_path
--display dialog msg buttons {"OK"} default button 1
my omniConvert(this_item, item_path, exp_path)
-- Uncomment this line if you have CocoThumb installed
-- my createThumb(exp_path)
end repeat
-- create icon with CocoThumbX
on createThumb(exp_path)
set theApplication to Drive:Applications:Tools:CocoThumbX"
set theFile to alias exp_path
tell application "Finder"
open theFile using theApplication
end tell
end createThumb
-- this sub-routine just comes up with the new name
on rename(item_name, item_ext, new_extension)
tell application "Finder"
if the item_ext is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of item_ext) + 2) of the item_name
end if
set target_name to (the trimmed_name & "." & new_extension) as string
end tell
return the target_name
end rename
-- this sub-routine does the export
on omniConvert(source_file, source_path, target_path)
with timeout of 900 seconds
tell application "OmniGraffle"
-- save the current export settings so we can replace them later
set oldAreaType to area type of current export settings
set oldBorder to include border of current export settings
set oldBackground to draws background of current export settings
-- here is where you set the export settings you want
set area type of current export settings to all graphics
set include border of current export settings to false
set draws background of current export settings to false
-- open the file if it isn't already open
set needToOpen to (count (documents whose path is source_path)) is 0
if needToOpen then
open source_file
end if
-- do the export
set docsWithPath to documents whose path is source_path
set theDoc to first item of docsWithPath
save theDoc in file target_path
-- if the file wasn't already open, close it again
if needToOpen then
close theDoc
end if
-- put the original export settings back
set area type of current export settings to oldAreaType
set include border of current export settings to oldBorder
set draws background of current export settings to oldBackground
end tell
end timeout
end omniConvert
</div></pre>Jens v.P.http://www.blogger.com/profile/14089732885850015120noreply@blogger.com0