Software & Manuals

How to Typeset Equations in LaTeX (New version!)

LaTeX is a very powerful tool for typesetting mathematical expressions. However, when looking at a typical document one often finds that mathematical equations that are too long to fit on one line or that consist of several equations in one block are often only poorly typeset in spite of the power of LaTeX.

This short introduction tries to show how a nice typesetting is done easily and efficiently. It includes an introduction to the less known, but very powerful tool "IEEEeqnarray".

Download:

More information about IEEEtran can be found on Michael Shell's website. An easy-to-read and very informative manual about LaTeX is The Not So Short Introduction to LaTeX 2ε by Tobias Oetiker.


My LaTeX-Stylefile: research19.sty (New version!)

This is my personal main LaTeX-stylefile (version 19.3, 2024/04/12) that I use everywhere and that makes sure that all my LaTeX-documents are set up the way I want. I simply include a line similar to

	    \usepackage[widelayout,sf,USenglish]{research19}
	  

You can find more info about possible options in the stylefile itself. The old version research18.sty (version 18.8, 2023/12/29) is still available for download.


English Grammar: Infinitive or ing-Form?

English is — in spite of what some people might say — a very difficult language. In particular it is very difficult to find rules that work. Nevertheless, I have tried to attack (or is it "try attacking"!?!) one of my biggest English difficulties: when to use the infinitive and when the ing-form... Perhaps this might be useful for you, too! In any case, I would be happy to receive feedback!

Download:


buha: Accounting Done Right

buha is a C++-program for simple and elegant financial accounting. Instead of keeping the financial data in error-prone Excel-sheets, that mix data with programming and are extremely hard to keep in order, buha keeps its data in simple text-files. With buha you easily keep track of various accounts, expenses and income, and double-entry bookkeeping becomes very simple. buha allows you to export all data in separate files, either in text-format, CSV-format, or in a format that allows import into LaTeX.

In the source code included is an toy example inclusive a LaTeX-file that imports all relevant data from the generated LaTeX-files and generates a complete financial report. An extract of this toy example looks as follows:

	      ...

	      \new acc		                Bank Account IBAN xxxx xxxx
	      \new cr			        Credit Card
	      \new expenses		        Expenses

	      \new 01		                Food
	      \new 02			        Communication 

	      ...
	      
	      \date 5/3/2021
	      01 - cr		123.05		shopping (credit card)
	      02 - acc	        45.40		phone bill January

	      ...
	      
	      \date 31/3
	      \saldo 01 > expenses		01 food
	      \saldo 02 > expenses		02 communication
	      	      
	      \show 
	    

The complete toy example is available here: ToyExample. The LaTeX-generated financial report produced by buha from this toy example can be downloaded here: summary.pdf.

For more details about buha look at the included README and the included summary.tex file.

Download:

The name "buha" is an abbreviation of the German "Buchhaltung" (accounting). The program was written by Hans-Andrea Loeliger in the 1990s and a huge Thank You goes to him! I only slightly adapted the code by adding a few things I needed. I publish the code here at Andi's express wish and with his permission.


grad: Book-Keeping of Grades and Exams (New Version from December 2023!)

grad is a C++-program that elegantly keeps track of various exams and grades for a class of students. Instead of keeping the grades and points in error-prone Excel-sheets that mix data with programming and are extremely hard to keep in order, grad keeps its data in simple text-files. With grad you easily compute grades from points, take weighted averages of different grades/exams to compute final grades, and directly generate LaTeX-code that allows you to produce elegant tables of the results of your exams and your grading.

A toy example of a grad data file looks as follows:

	      \reset

	      \student alice      Miller Alice
	      \student bob	  Smith Bob
	      \student eve  	  White Eve

	      \grade oral1  1     oral grade 1
	      oral1 - alice    4.5
	      oral1 - bob      5
	      oral1 - eve      5.25

	      \grade oral2  1     oral grade 2
	      oral2 - alice    5.25
	      oral2 - bob      6

	      \grade oral 0.5     final oral grade (weight 0.5)
	      \avg oral < oral1 oral2

	      %% written exam "wr" of weight of 1.5 with linear
	      %% scale where 48 points correspond to a grade 4, and
	      %% 80 points correspond to a grade 6
	      \exam wr 1.5 48 4 80 6	written exam
	      wr - alice    1   9  12   1   9   4
	      wr - bob     12  12  11  20   0   3
	      wr - eve     10  21   5  12  17  12
	      \sort g wr
			  
	      \rounding 0.5	  
	      \grade final 0      final grade   
    	      \avg final < wr oral

	      \show 
	    

Two examples of LaTeX-files that grad produced from this toy example are available here: wr.pdf and z_overview.pdf.

For more details about grad look at the included README and the given more detailed example.

Download:

The foundations of grad lie in buha: the basic structure of the code like menu, input parsing, list structure and booking are taken over almost unchanged. Instead of accounts, grad has two separate entities, namely exams/grades and students.


mygpg: Secure Password-File Management based on Perl and GPG

The number of passwords that I should be able to remember nowadays is far over 100. So unless I choose them all to be all the same or use some other very insecure tricks, the only way to survive is to keep a file with them written down. However, among all tricks that help with remembering passwords, this is about the most insecure and silly thing to do...!

My solution is to keep a password file, but to have it securely encrypted using one of the best encryption standard there is: the open-source and free program GPG. I use a separate and unpublished private/public key-pair only for that particular file. For more details about GPG, see my How-To of GPG.

So the only problem is how to access and edit the secure password file. I do not want to store the passwords unencrypted on my harddrive at any time, not even temporarily for editing! For that reason I have written a small script mygpg that accesses the file, decrypts it, invokes Emacs, and passes the decrypted information into a buffer of Emacs. At the end Emacs will take care of the encryption and will write the encrypted file back to disk. The unencrypted information is never stored anywhere but solely kept in the memory of the computer during the accessing/editing time.

System Requirements:

  • any UNIX-like system like Mac OS X
  • perl including perl-package Term::ReadKey and IPC:Run3 (use cpan Term::ReadKey and cpan IPC:Run3 to install)
  • gpg (fully set up)
  • Emacs

Installation:

  • Download mygpg (version 4.4, March 2019) and decompress it.
  • Put it anywhere you like, e.g., into ~/bin/, and make sure that the executable bits are set ("chmod a+x ~/bin/mygpg")
  • Edit the file "mygpg" and change the value of the variables "$file" and "$gpgcommand" according to your encrypted file and the correct encryption command.

Usage: For normal use simply call "mygpg". The optional argument "-h" will print a short help message and exit. For calling Emacs inside the terminal (e.g., if there is no X11 environment) use the option "-t". For only reading the file without the possibility to edit, the file can also be displayed using 'less'. To do so, use the option "-l". To create an empty password file, use the option "-c".


GnuPG: A Mini How-To

This very brief introduction to GPG is already some years old, but it should still be up-to-date (more or less...). I hope it is useful...
GnuPG for daily use: a mini How-To


Typesetting Chinese Characters in LaTeX: A very quick manual

Typesetting Chinese in LaTeX used to be quite a headache. I remember spending hours and hours in trying to set my system up. In the meantime, things have simplified considerably (or I have simply learned how to do it properly...). Here are some very brief instructions on how to proceed.

I distinguish two different situations: the case where I want to compose a large document containing a lot of Chinese characters and the case where I only need to incorporate a few Chinese characters (like, e.g., my Chinese name) in a otherwise Western document.

  • Large Chinese LaTeX document: Here the way to go is to use XeLaTeX. Every modern LaTeX installation comes with that fully functional, i.e., the setup should be trivial: you only need to include some packages and define the font. Try the following:
    		\documentclass[a4paper,12pt]{article}
    		
    		\usepackage{fontspec}
    		\usepackage{xeCJK}
    		\setmainfont{Times}
    		\setCJKmainfont{BiauKai}
    		
    		\begin{document}
    		
    		Simply type some Chinese text like 莫詩台方 and English text intermixed.
    		
    		\end{document}
    	      
    Here, we have defined the default font of English text to be Times and the the Chinese characters will use BiauKai (this is the default Chinese font on Mac OS X for traditional Chinese). You can use any other font that is installed on your system. Simply check the names of your available fonts using any other typesetting tool like Word or similar.
    Instead of the usual latex, the document has now to be compiled using the command xelatex, which will generate a PDF directly.
    A couple of comments:
    • Do not use the package inputenc. The behavior of inputenc is already included in XeLaTeX.
    • XeLaTeX will automatically figure out what part of the text is in Chinese and what not. However, sometimes this decision might turn out wrong (for example for punctuation signs). Then you can force the choice using the fontspec-command:
      		    \fontspec{BiauKai}ˇ
      		    \fontspec{Times}ˇ
      		  
    • The real strength of XeLaTeX is that any font available on your system can be used. This is also true for the English font. Try for example:
      		    \setmainfont{Zapfino}
      		  
  • Only add a few Chinese characters in you LaTeX document: Here, you can keep using the normal LaTeX and add some more packages. Try the following:
    		\documentclass[a4paper,12pt]{article}
    		
    		\usepackage[encapsulated]{CJK} 
    		\usepackage{ucs}
    		\usepackage[utf8x]{inputenc} 
    		\newcommand{\cjktexta}[1]{\protect\begin{CJK*}{UTF8}{bkai}#1\end{CJK*}}
    		\newcommand{\cjktextb}[1]{\protect\begin{CJK*}{UTF8}{bsmi}#1\end{CJK*}}
    		
    		\begin{document}
    		
    		The Chinese characters can now be typed using the cjktexta- and
    		cjktextb-commands as follows: \cjktexta{莫詩台方} and \cjktextb{莫詩台方}.
    		The two versions result in a different font.
    		
    		\end{document}
    	      
    This document can now be compiled using the normal latex or pdflatex command.

Various Useful Shell-Scripts

Installation: To install any of these scripts, download the script, decompress it, and put it anywhere you like, e.g., into ~/bin/. Then make sure that the executable flags are set (chmod a+x script-name).

Usage: Simply type the name of the script into a terminal.

mp3move

The script mp3move (version 4.1, April 2009) is a script that I wrote when I needed to arrange the files on a MP3-CD: the script renames all files in the current directory as follows: firstly a given number of letters is removed from the filename starting at a given position (e.g., removing an old counting), then a new consecutive numbering is added in place of the removed letters. The numbering starts at a given point and has a fixed number of positions.

multicopy

The script multicopy (version 2.3, April 2018) copies all files starting with a certain string to a new file with a new name, preserving the original ending of the filename.

multimove

The script multimove (version 2.2, September 2010) renames all files starting with a certain string, preserving the original ending of the filename.

pdfa4toletter

The script pdfa4toletter (version 1.1, May 2021) converts a pdf-file in a4 format into letter format by cropping, not scaling. For more info, type "pdfa4toletter" without arguments.
Requirements: This script requires pdfjam to be installed on your system.

pdfinsert (New version!)

The script pdfinsert (version 2.0, February 2024) inserts a pdf-file into another one at a specified page. For more info, type "pdfinsert" without arguments.
Requirements: This script requires pdfjam to be installed on your system.

pdfinterlace

The script pdfinterlace (version 1.4, September 2022) assumes that you have scanned a pile of double-sided pages by first scanning all odd pages and then flipping the whole pile and scanning the backside of them (in backwards order). Thus, the obtained pages are in a wrong order. This script now resorts all these pages in the correct order. For more info, type "pdfinterlace -h".
Requirements: This script requires pdfjam, xpdf, and pdfselect.

pdflettertoa4

The script pdflettertoa4 (version 1.1, May 2021) converts a pdf-file in letter format into a4 format by cropping, not scaling. For more info, type "pdflettertoa4" without arguments.
Requirements: This script requires pdfjam to be installed on your system.

pdfnupsmart

The script pdfnupsmart (version 1.2, May 2021) rearranges the pages of a pdf-file: two pages are put onto one page in such a way that the odd pages are on the right-hand side like in an open book. Moreover, to avoid problems with some printers, the file is then rotated to normal portrait style.
Requirements: This script requires pdfjam to be installed on your system.

pdfselect

The script pdfselect (version 2.0, January 2023) lets you pick an arbitrary range of pages from a pdf-file, similarly to psselect. In addition, with a range specification 's', it splits the pdf-file page-by-page into single-paged pdf-files. For more info, type "pdfselect" without arguments.
Requirements: This script requires pdfjam and xpdf.

prefixadd

The script prefixadd (version 1.0, October 2010) adds a prefix to all files ending with a particular string.

smv

The script smv (version 1.0, August 2015) is a 'save-move' command: it executes "mv", but with filenames being changed with an added numeral in case the filename exists already at the destination. For more info, type "smv" without arguments.

stuffzeros

When exporting photos from iPhoto, the numbering system is not UNIX-like: they are called photo-1.jpg, photo-2.jpg, ..., photo-10.jpg, etc. This way the numbering is not in alphabetical order which can cause problems with other programs. The script stuffzeros (version 3.2, June 2009) automatically corrects this. It will add zeros in front of the numbers so that the files afterwards are named photo-01.jpg, photo-02.jpg, ..., photo-10.jpg, etc.

suffixadd

The script suffixadd (version 2.1, October 2008) adds a suffix to all files starting with a particular string.

timer: A Simple Stopwatch in the Terminal (version 3.6, June 2018)

I sometimes need to have a simple stopwatch or timer (version 3.6, June 2018) handy, so I wrote this small Perl-script. Maybe someone else might find it useful, too...
Requirements: Your perl-system needs to have the perl-package Term::ReadKey installed (use cpan Term::ReadKey to install)

watchdog

The script watchdog (version 1.1, October 2008) regularly checks a file and informs by email if the file has been modified. This is done either once, or continuously until the file is renamed or deleted.


addrbook: Address-Management with Perl and LaTeX

Most available address-management tools have either too many or too few features for me. I have therefore started writing a small (partially LaTeX-based) Perl-script that takes care of my addresses: I keep an ASCII-file with the necessary information (name, address, telephone, email, birthday, remarks). The script then generates (via LaTeX) a printable version that I can carry with me. The advantages are obvious:

  • in a common address booklet with hand-written entries space is always too limited in some parts of the alphabet, while in other parts most entries are empty...;
  • if I lose my address-book, I just print it out again;
  • I do not need any computer, battery or what-so-ever to check addresses, however,
  • if I am online, I can search for addresses electronically;
  • I have added a lot of small additional features like
    • automatic alphabetical ordering
    • sub-groups of people (e.g., friends, business relations, emergency numbers, etc.)
    • listing of birth dates
    • an automatic birthday reminder e-mail
    • a web-interface for online search of your addresses! This can be included into your homepage as shown for example here.
    • The most recent feature is a calendar reminder system: either birth dates or general calendar entries (from a different data-file that contains calendar entries instead of address entries) will be sent by e-mail at the corresponding day as reminder!
Here you can have a look at

System Requirements: Any Unix-flavored system or Mac OS X with working Perl and LaTeX. For usage as (birthday or general) reminder system and for electronic search of entries (including the web-based version) no LaTeX is needed.

Download:

The program is freeware, but I would be very happy if you let me know () in case you consider using it.

If you want to be informed about updates, please send me an email, I will put you on my mailing list (don't worry, you won't get many emails if you do so!).


afptunnel: Secure AFP-Connections (Apple File Protocol) via SSH Tunnel

System Requirements: Apple computer with macOS

Problem: You are using your laptop (or another computer) away from home and would like to access your files at home. Apple offers the convenient AFP connection ("Connect to Server..." or command-K). However, if you do not have the Mac OS X Server version there is no way to make this connection secure, i.e., everything that is transmitted over the Internet is clear-text, including your login and password! Furthermore, you have to open your computer at home to the world which includes a guest-access. While the guest-access is restricted, of course, you still might feel uncomfortable with it, particularly if you are sure that you actually do not need it.

Solution: Open a SSH connection to your home computer (the remote computer) and then pipe your standard AFP connection through this SSH tunnel. Unfortunately, the commands to do so are very UNIX-like and cryptic. I have therefore written a small shell-script that will do everything for you. You only need to follow the following steps:

  • Start the terminal and type "afptunnel"
  • Provide your password when prompted
  • The normal "Connect to Server..."-dialog appears: log in as usual
  • The connection you establish is both secure and compressed, i.e., you even save bandwidth!
  • When you have finished, unmount your files by clicking on the eject button or by dragging it to the trash
  • Press enter in the terminal to disconnect the SSH tunnel.

Installation:

  • Download afptunnel (version 2.2, December 2008) and decompress it.
  • Put it anywhere you like, e.g., into ~/bin/, and make sure that the executable bits are set ("chmod a+x ~/bin/afptunnel")
  • Edit the file "afptunnel" and change the value of the variable "TARGET_HOST" to match the IP-address of your home computer
  • On your remote computer (at home) open the System Preferences:
    • Sharing->activate Personal File Sharing
    • Sharing->activate Remote Login
  • If you want to disable the guest-access (and any other access that does not use the secure SSH connection), you need to setup your firewall to block Port 548. This way the "Personal File Sharing" Service is blocked from outside and only available within your computer. Unfortunately, you cannot edit the OS X built-in firewall to do exactly this while Personal File Sharing is active. You need another interface to the firewall. A possible solution is the shareware tool Flying Buttress. A standard setting would be, e.g., about as follows:
    • Outgoing: Allow
    • Incoming: Deny
    • Remote Login (SSH): Allow TCP from Internet (any Port) to MyComputer (Port 22)
    With such a setup you actually block everything apart from SSH.
    Another possibility is to manage the firewall manually as described in Exploring the Mac OS X Firewall.

For more options of afptunnel type "afptunnel -h".


mailtunnel: Sending Mails If You Do Not Have an SMTP Server

System Requirements: Any UNIX-like system like macOS.

Problem: You are using your laptop abroad and would like to send some email. Usually you then get into problems because you either

  • don't know the SMTP server of the net-access you are using,
  • there is no SMTP server on the net-access you are using, or
  • you don't trust the SMTP server of the net-access you are using.

Solution: Open a SSH connection to your home computer (the remote computer) and then relay your mails via your home computer to your usual SMTP server at home. This way your mails look like being sent from home, your mails are securely sent through the unknown net-access you are using, and your mails are even compressed in case your net-access is slow! You only need to follow the following steps:

  • Start the terminal and type "mailtunnel"
  • Provide your password when prompted
  • Tell your mail-program to use "localhost" at port 1025 as SMTP server
  • When you have finished, quit your mail program and press enter in the terminal to disconnect the SSH tunnel.

Installation:

  • Download mailtunnel (version 1.4, November 2021) and decompress it.
  • Put it anywhere you like, e.g., into ~/bin/, and make sure that the executable bits are set ("chmod a+x ~/bin/mailtunnel")
  • Edit the file "mailtunnel" and change the value of the variable "TARGET_HOST" to match the IP-address of your home computer and the value of the variable "SMTP_HOST" to match the IP-address of your usual SMTP server at home
  • On your remote computer (at home) open the System Preferences->Sharing->activate Remote Login

For more options of mailtunnel type "mailtunnel -h".



-||-   _|_ _|_     /    __|__   Stefan M. Moser
[-]     --__|__   /__\    /__   Senior Scientist, ETH Zurich, Switzerland
_|_     -- --|-    _     /  /   Adjunct Professor, National Yang Ming Chiao Tung University, Taiwan
/ \     []  \|    |_|   / \/    Web: https://moser-isi.ethz.ch/


Last modified: Fri Apr 19 10:25:05 UTC 2024