Rob's Unix Tip of the Day File

You are in: Robert Whittaker » Research » Unix Tip of the Day

A collection of Linux and LaTeX related tricks and hacks that I've found useful over the years. Appologies for the fact that it's in plain text, and the entries are completely uncategorised. The content below originates from a text file in my home directory, and I'm afraid I've never found the time to sort it out properly.

---------------------------------------------------------------------
PREVENTING DELAYED PLACEMENT OF LATEX FLOATS (2017-02-07)

Suggested code to allow a larger fraction of floats on a page before
LaTeX places the floats on their own page and delays the placement:

  \renewcommand{\topfraction}{0.9}       % max fraction of floats at top
  \renewcommand{\bottomfraction}{0.8}    % max fraction of floats at bottom
  \renewcommand{\textfraction}{0.07}     % allow minimal text w. figs
  \renewcommand{\floatpagefraction}{0.7} % require fuller float pages

See http://aty.sdsu.edu/bibliog/latex/floats.html

---------------------------------------------------------------------
CUSTOMIZE METACITY KEYBOARD SHORTCUTS IN UBUNTU > 14.x (2016-03-18)

The shortcuts (e.g. to switch workspaces and to move windows from
workspace to another) are now somewhat hidden, but can be accessed
using dconf-editor. They are stored in the location

  org.gnome.desktop.wm.keybindings

---------------------------------------------------------------------
BROKEN TITLES IN PDF FILES FROM LATEX USING DVIPS (2015-12-07)

If using latex -> dvips -> ps2pdf to generate PDF files from LaTeX,
the title in the PDF metadata can get messed up by dvips incorrectly
using titles from included eps graphics files. There are a few
solutions, including using pdflatex directly or having a script to
remove the offending SDict lines from the generated ps file.

For more details see:
http://www.sergioller.com/2011-07-07-gnuplot-breaks-LaTeX-pdf-title.md
http://www.latex-community.org/forum/viewtopic.php?f=5&t=16280

---------------------------------------------------------------------
REMOVE METADATA FROM A PDF FILE

See https://gist.github.com/hubgit/6078384

---------------------------------------------------------------------
ADD AN SSL CERTIFICATE TO CHROMIUM ON LINUX (2014-05-15)

Click on the lock on the location bar and view the certificate
details. Save the certificate as "Base 64 ACSII (single certificate)"
with a name such as cert.pem. Make sure the libnss3-tools package is
installed. Then run:

  certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n cert.pem -i cert.pem

Check the certificates installed using

  certutil -d sql:$HOME/.pki/nssdb -L

See: http://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate

---------------------------------------------------------------------
FONTS IN PNG TERMINAL IN GNUPLOT ON LINUX (2014-02-04)

Access TTF fonts by provising the full path to the .ttf file. e.g.

set term png font "/urs/share/fonts/truetytpe/freefont/FreeSans.ttf,12"

---------------------------------------------------------------------
CORRUPTED PDF FILES WHEN SAVED FROM FIREFOX'S BUILT-IN PDF VIEWER

See https://support.mozilla.org/en-US/questions/972500 for a
description of the problem and a solution. Apparently it should be
fixed anyway in Firefox 26.

---------------------------------------------------------------------
FIX "Message to save shrank" ERROR ON PINE WHEN USING EXCHANGE IMAP

Possible solution for Exchange 2010 found at
http://social.technet.microsoft.com/Forums/en/exchange2010/thread/551d57f6-fcd6-4bc4-940c-704e2c94beb7

"The solution is on a per-user basis to use Set-CASMailbox user
-ImapUseProtocolDefaults:$false -ImapEnableExactRFC822Size:$true or on
a server basis use Set-ImapSettings -EnableExactRFC822Size:$true

Note that it will require additional overhead so I'd suggest only
enabling the option for people using clients that exhibit the
issue. Pine/Alpine is one and I've heard it reported with Thunderbird
also."

---------------------------------------------------------------------
SSH TUNNEL FOR WEB TRAFFIC WITHOUT A REMOTE PROXY SERVER (2012-06-28)

It is often useful to make your web traffic appear that it comes from
a different computer. For instance my University has access to many
online journals, and web requests from a University computer have
access without needing to log in.

I had previously been using PuTTY to forward a local port on my home
Windows computer to the appropriate port on my University's web cache
server. My new University doesn't run a web cache / proxy so this
method no longer works.

However it is still possible to use such such forwarding
mechanism. There are two stages:

1/ Set up your SSH client (eg PuTTY) to do a dynamic forward of a
(local) port, say 8080.

2/ Then configure your web browser to to use localhost:8080 as a SOCKS
proxy.

(If you want your DNS requests to also go via the tunnel, you can set
the Firefox setting network.proxy.socks_remote_dns to true.)

For more detailed instructions, see
http://www.extremetech.com/computing/93106-escaping-the-firewall-with-an-ssh-tunnel-socks-proxy-and-putty

---------------------------------------------------------------------
USE CYGWIN TO CREATE A PORTABLE WINDOWS EXE FROM C++ CODE (2012-02-24)

  g++-3 -mno-cygwin *.cpp

---------------------------------------------------------------------
CONVERT AN A4 PS FILE INTO A CROPPED EPS FILE (2012-02-23)

Some journals require figures as a single .eps file, whereas I
normally work with a combined eps+latex approach when generating
figures from Gnuplot and XFig. To convert the figures from my working
format to the requires eps format, I run a separate LaTeX document to
render each figure. This gets me an A4 ps file, that needs to be
converted to a cropped .eps file. To do this last step run:

  ps2eps -B -C figure.ps
  eps2eps -dNOCACHE figure.eps figure2.eps

The dNOCACHE option ensures that fonts aren't converted to bitmaps
(thanks to
http://www.physics.utoronto.ca/~szhukov/home/Code_snippets/Entries/2011/4/28_eps2eps__Avoid_bitmap_fonts_during_PostScript_conversion.html
)

---------------------------------------------------------------------
MAKE EPS+LATEX FILE FROM A FIG ON THE COMMAND LINE (2012-01-10)

To convert a *.fig file to eps+latex using the command line rather
than XFig, you can use the fig2dev program. You need to run it twice:
once to produce the *.pstex image file, and once to produce the
*.pstex_t LaTeX picture file. You also need to provide the name of the
*.pstex image to include in the *.pstex_t file. So:

  fig2dev -L pstex foo.fig > foo.pstex
  fig2dev -L pstex_t -p foo.pstex foo.fig > foo.pstex_t

---------------------------------------------------------------------
C-x, C-c DOESN'T WORK IN EMACS ON CYGWIN (2011-11-20)

There is some interaction between C-c as an interrupt on Cygwin and
the C-c key combination in Emacs. The solution given in
http://superuser.com/questions/93771/c-x-c-c-not-working-in-emacs-23-1
of adding a Windows environment variable CYGWIN=tty fixed the problem
for me.

---------------------------------------------------------------------
STOP EMACS LATEX MODE FORMATTING SUB- AND SUPER-SCRIPS (2011-11-18)

Add the following to your .emacs file:

  (eval-after-load "tex-mode" '(fset 'tex-font-lock-suscript 'ignore)) 

---------------------------------------------------------------------
FIND YOUR .emacs FILE ON WINDOWS (2011-11-18)

  C-x C-f ~/.emacs

since ~ will be expanded to whatever emacs things your home directory
is.

---------------------------------------------------------------------
AUTOMATICALLY CONVERT EPS FILES TO PDF WITH PDFLATEX (2011-09-18)

Add the following to the LaTeX preamble, *after* loading graphics or
graphicx:

  \usepackage{epstopdf}

----------------------------------------------------------------------
USE ACROBAT READER (OR SOME OTHER SPECIFIC PROGRAM)  (2011-02-18)
TO OPEN PDF ATTACHMENTS IN PINE

The way attachments are handled in pine is controlled by two sets of
settings files. The first 'mime-types' controls detection of what type
of tile the attachment is. The second 'mailcap' defines which program
should be used for opening files of a given type.

It's the second of these we need to alter in order to set a specific
program for a specific file type. The default Unix pine configuration
has a system-wide mailcap file, but will also look for ~/.mailcap --
any settings found there will over-ride corresponding settings in the
system file.

To use acrobat for PDF files, I created ~/.mailcap and added the
following line (based on what was already in the system file at
/etc/mailcap):

  application/pdf; acroread '%s'; nametemplate=%s.pdf; test=test "$DISPLAY" != ""

----------------------------------------------------------------------
PREVENT IDLE SSH CONNECTIONS FROM TIMING OUT (2010-09-03)

Some networks will time out idle ssh connections after 10 minutes or
so. This is annoying if you want to ssh to another computer to read
email etc and want to retain the connection throughout the day.

The solution is to set the ssh client or server to send regular 'keep
alive' packets through the connection to avoid the network form
thinking it's idle.

To achieve this as a regular user, add the following line to your
~/.ssh/config file (which may need to be created first):

  ServerAliveInterval 60 

which will then send packets every 60 seconds.

----------------------------------------------------------------------
CHANGE THE FILL COLUMN in EMACS (2010-07-02)

Using M-q in emacs executes the fill-paragraph command, which
word-wraps the lines to a standard width. That width can be changed by
setting the value of 'fill-column'. The easy way to do this is to
position the mark in the column you want, and then do C-u C-x f.

----------------------------------------------------------------------
PREVENT BIBTEX FROM ADDING NON-CITED CROSS-REF'D ENTRIES (2010-04-08)

A feature of BibTeX means that if you use cross-referencing and then
cite two or more items that cross-reference the same source, then the
source gets added to the bibliography as a separate item. This may not
be desirable.

To prevent this behaviour (or to alter the number of cross-references
required) you can use the 'min-crossrefs' option when running BibTeX.
To turn the feature off completely, add a very large number, eg

  bibtex --min-crossrefs=500

If you run BibTeX from emacs using C-C,TAB, then you can change the
default by adding the following to your .emacs file:

  (setq tex-bibtex-command "bibtex --min-crossrefs=500")

----------------------------------------------------------------------
CONVERT FILES FROM PDF TO EPS (2009-10-06)

Use pdftops with the -eps option, ie

  pdftops -eps file.pdf

This only works if your PDF file has only one page (since EPS files
can't have pages). If you have a multi-page PDF and want each page as
a separate EPS file, then first split it using pdftk from
http://www.accesspdf.com/pdftk/

  pdftk multipage-file.pdf burst

If you have a multipage PDF file and you want to extract bitmap images
it contains, then you can do this with pdfimages

  pdfimage -f<firstpage> -l<lastpage> file.pdf

This will output a set of .pbm and ppm files, which can be converted
to other formats using the convert utility from ImageMagick.


----------------------------------------------------------------------
FIX KEYBOARD REPEAT DELAY ON UBUNTU LAPTOP (2009-09-20)

Using Ubuntu on my Lenovo ThinkPad, the initial keyboard repeat delay
was too short and the repeat rate too high. For some reason the
graphical utility that should let you change this (System ->
Preferences -> Keyboard) has no effect.

http://ubuntuforums.org/showthread.php?t=1003806 provides the
following solution:

Use the command

  kbdrate -r 24 -d 750

with sudo if necessary to adjust the rate and delay. Add this command
to /etc/rc.local to have it executed each time on startup.

And

  xset r rate 750 24

has a similar effect. But unfortunately neither affected the delay
when using my wireless pointer, so I still need to be careful not to
let me finger linger on the 'next slide' button for too long.

----------------------------------------------------------------------
BETTER HYPHENATION IN LATEX WITH \RAGGEDRIGHT (2009-09-16)

Although I don't like using ragged right for documents, it's often
mandated when writing grant proposals. However, LaTeX's standard
hyphenation rules seem to overly discourage hyphenation when
\raggedright is in effect. This results in a poor visual result and
wasted space.

To overcome this, and get better hyphenation, try the ragged2e package, with

  \usepackage[newcommands]{ragged2e}

the 'newcommands' option redefines the existing \raggedright etc
commands to use the improved version. For details see:

http://www.ctan.org/tex-archive/help/Catalogue/entries/ragged2e.html

----------------------------------------------------------------------
CROSSING OUT TERMS IN A LATEX EXPRESSION (2009-09-10)

The cross out a whole term in a LaTeX expression (eg because it it
zero) you can use the "cancel" package, followed by \cancel, \bcancl,
\xcancel, or \cancelto.

  http://www.ctan.org/tex-archive/help/Catalogue/entries/cancel.html

----------------------------------------------------------------------
LOGITECH CORDLESS 2.4 GHz PRESENTER on LINUX (2009-08-14)

http://www.logitech.com/index.cfm/mice_pointers/presentation_remote/devices/175

I recently purchased the above device which includes a laser pointer
and a wireless forwards and back button for giving slide shows from a
computer. I was specifically looking for something that would work
with Linux and Adobe Reader, and not just PowerPoint on Windows.

Fortunately I wasn't disappointed and the device works seamlessly (you
just have to pug in the USB receiver) on my Ubuntu desktop. Even the
volume control worked. (The start presentation and black screen
buttons send F5/Esc and '.', which are PowerPoint-specific, but other
presentation apps may use them too.) It also worked on a colleague's
Mac. The computer initially made a bit of a fuss about what sort of
keyboard I was plugging in, but we told it it was some generic one and
everything worked.

----------------------------------------------------------------------
BULK UPDATE OF SYMLINK TARGETS (2009-05-12)

My sys-admin has recently moved the location of our home directories,
and as a result a bunch of symlinks have been broken. The following
command-line script finds all symlinks under the current directory,
and replaces 'old' with 'new' in their targets:

  for a in `find . -type l`; do
    b=`readlink $a | sed 's/old/new/'`;
    echo $a;
    ln -sf $b $a;
    done


----------------------------------------------------------------------
FIXES FOR THE OXFORD DEBIAN -> UBUNTU UPGRADE (2009-01-08)

We've just had our computers upgraded from Debian to Ubuntu, and as a
result several aspects of the desktop environment were changed
(Metacity to Compiz) and various annoyances introduced. Here's my list
of fixes to get things back how I want them:

 * Fix size of desktop switcher in panel (half-height for some reason)
   and turn off the annoying sliding animation when moving between
   desktop screens: Main Menu > System > Preferences > Appearance >
   Visual Effects > None (You'll also loose several other eye-candy'
   effects by doing this, but I don't think that's a great loss.)

 * Get Alpine (the new Pine) working properly with UTF-8 encoded
   messages. Alpine can handle UTF-8 properly, but it needs to be in a
   UTF-8 enabled terminal with a UTF-8 encoding set. The following
   worked for me *after logging in again* (apparently different
   gnome-terminal's can't have more than one charset in a session).
   Add the following to your ~/.bashrc-user file:

     export LANG=en_GB.UTF-8
     export GDM_LANG=en_GB.UTF-8

 * Get the Computer, Home, and Trash (aka Recycle Bin, Deleted Items)
   icons back on the desktop: In a terminal type gconf-editor, and
   then go: apps > nautilus > desktop. Add ticks next to the icons you
   want to see. Re Trash -- at first it didn't change the icon
   according to whether it was full or empty. It worked after the next
   login. According to some web sites, you may need to add the Trash
   icon to your panel and then remove it for the desktop one to start
   working.

 * Remove the emacs splash screen that's now shown on each startup.
   Add the following to your ~/.emacs file:

     ;; do not display a splash screen on startup
     (setq inhibit-splash-screen t)

 * Re-enable the middle-click-paste-open-url functionality in Firefox.
   (This feature was deliberately removed by Ubuntu:
   https://launchpad.net/ubuntu/+source/firefox/+bug/8647) Enter
   'about:config' in the firefox address bar, and search for the
   preference 'middlemouse.contentLoadURL'. Double click to change it
   from 'false' to 'true'.

 * Get emacs to use a British English dictionary (rather than the
   America dictionary it now defaults to): Add the following to your
   ~/.emacs file:

     ; Set dictionary to British rather than the default American
     (setq ispell-dictionary "british")
     (setq ispell-local-dictionary "british")

----------------------------------------------------------------------
HAVE WGET IGNORE ANY ROBOTS.TXT FILES IT ENCOUNTERS (2008-10-16)

Use:

  wget -erobots=off http://www.example.org/

----------------------------------------------------------------------
PRINTING UTF-8 WITH PERL (2008-07-09)

Apparently if you try to print a string containing UTF-8-encoded
characters with Perl, strange things can happen with characters that
can be presented in ISO-8859-1. It appears that strings containing
only ASCII characters are fine, as are strings with higher-valued
characters with no latin-1 counterpart. However strings containing
only characters from the latin-1 set are output with the latin-1
encoding.

The solution (for printing to stdout) is include the following line in
your code:

    binmode STDOUT, ':utf8';

For more details see: http://perldoc.perl.org/functions/binmode.html

----------------------------------------------------------------------
FIREFOX STATUS BAR TEXT MISSING DESCENDERS ON WINDOWS (2008-07-07)

In my newly installed firefox 3 on windows, I had a problem with
descenders being missed off the text in the status bar. A few pixels
were missing so underscores appears as spaces, "q" as an "a", etc.

Thanks to http://www.yabfog.com/wp/2008/06/20/firefox-3-display-bugs
and http://forums.ensolis.com/viewtopic.php?f=4&t=158 I've discovered
the cause and a solution. It appears that problem is due to a Gecko
bug (https://bugzilla.mozilla.org/show_bug.cgi?id=417259) that only
manifests itself due to a chrome CSS setting made in this case by the
forcastfox extension.

The workaround is to add the following to your userChrome.css file:

  statusbar#status-bar {
    overflow-x : visible !important;
  }

----------------------------------------------------------------------
AUTO EXPORT BOOKMARKS FROM FIREFOX 3 (2008-06-16)

Thanks to http://kevin.colyar.net/posts/show/4

  As of Firefox 3, bookmarks are saved in a places.sqlite database
  file instead of the usual bookmarks.html file. ... To fix this, you
  can configure Firefox 3 to auto-export your bookmarks to your
  bookmarks.html file. To do this, enter about:config in your browser
  location bar and change the browser.bookmarks.autoExportHTML key to
  true. Now when you exit Firefox, your bookmarks will be written to
  your bookmarks.html file

This functionality is useful to me to allow me to automatically copy
my bookmarks file to a web page, for easy access from anywhere I
happen to be online.


----------------------------------------------------------------------
PREVENT EMACS LEAVING SEMANTIC.CACHE FILES ALL OVER THE PLACE (2008-05-15)

Add the following to your .emacs file

  (setq semanticdb-default-save-directory "~/.semantic")

where ~/.semantic can be a directory of your choice.

----------------------------------------------------------------------
DISABLE SITE-WIDE LOADING OF AUCTEX IN EMACS (2008-05-15)

It appears that in Debian, the emacs package auctex gets loaded
automatically (presumably from a site-start.el file or similar). This
may not be what you want, and personally I find auctex very annoying
(especially the change in font size and face).

One way to prevent auctex being loaded in this way (along with other
local customisations) is to run emacs with the command:

  emacs --no-site-file

Alternatively you can create an alias in your .bashrc file to use the
above form when you type 'emacs':

  alias emacs='emacs --no-site-file'

However, this method has the disadvantage of disabling all
customisations that may have been applied locally, and also may not
affect any copies of emacs run by your window manage or called as a
helper application from other programs.

A better way to disable auctex is to add the following to you ~/.emacs
startup file:

  (if (featurep 'tex-site) (unload-feature 'tex-site t))

This looks to see if auctex has been loaded, and if so unloads it.


----------------------------------------------------------------------
FIND OUT IF A CERTAIN PACKAGE IS INSTALLED ON DEBIAN (2008-05-09)

  apt-cache policy <package-name>

----------------------------------------------------------------------
AVOID SPELL-CHECKING ARGUMENTS OF CERTAIN LATEX COMMANDS

Need to customise the list:

  ispell-tex-skip-alists


----------------------------------------------------------------------
BEWARE THE APACHE OPTIONS DIRECTIVE IN .HTACCESS

If you use an Options directive in an .htaccess file, it appears that
a statement such as

  Options MultiViews

will be read in preference to any other Options directives in force
and over-ride them, meaning that "MultiViews" is now the only option
in force in that directory. The effects are not cumulative, unless
explicitly stated by using the "+" modifier. So what you probably want
to use is:

  Options +MultiViews

which leaves any other options implemented in other places intact.

(This was causing me problems when trying to use mod_rewrite.
"RewriteEngine on" and "Options MultiViews" both worked on their own,
but together a default "AllowSymLinks" or "AllowSymLinksIfOwnerMatch"
option was lost and then mod_rewrite threw lots of errors.)

----------------------------------------------------------------------
MAKING MOVIES TO EMBED IN A PDFLATEX PRESENTATION

Embedded movies will only work in adobe reader on windows, and seem to
need to be an .avi file. These can be created from a set of frames in
.jpg format using the following command:

   mencoder "mf://*.jpg" -mf fps=25 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

See: http://electron.mit.edu/~gsteele/ffmpeg/

----------------------------------------------------------------------
PROBLEM SETTING PDF META-DATA FROM LATEX USING GNUPLOT 4.2 EPSLATEX TERMINAL

As described at http://www.cl.cam.ac.uk/~mgk25/publ-tips/#pdfmark you
can set various bits of PDF meta-data from within latex.

However, in gnuplot 4.2, the epslatex terminal produces eps files
which also contain 'pdfmark' commands for setting the pdf meta-data.
Unfortunately when such files are included in a LaTeX file, the
included author, title, etc can over-write those specified from within
LaTeX when a PostScript file is converted to PDF.

One possible kludge is to redefine the pdfmark command after the
correct meta-data has been issued, so that any future invocations have
no effect. This may have other unintended side effects though.

  \special{! /pdfmark where
             {pop} {userdict /pdfmark /cleartomark load put} ifelse
             [ /Author (Markus G. Kuhn, Ross J. Anderson)
               /Title (Soft Tempest: Hidden Data Transmission
                       Using Electromagnetic Emanations)
               /Keywords (compromising emanations, data security,
                          eavesdropping)
               /DOCINFO pdfmark
             userdict /pdfmark /cleartomark load put  }

Usenet discussion of the problem:
http://groups.google.com/group/comp.graphics.apps.gnuplot/browse_thread/thread/5938f08fe95b0bdd/469c49b8f2bc57a8

----------------------------------------------------------------------
FIREFOX HACKS

Set browser.backspace_action to 0 to make backspace go back in history
rather than up the page in Linux.

----------------------------------------------------------------------
CONVERT A COLOUR POSTSCRIPT FILE TO GREY-SCALE / BLACK AND WHITE

See: http://www-hermes.desy.de/notes/extras/postscript.html

----------------------------------------------------------------------
ALLOW PLAYING OF AMAZON REALAUDIO CLIPS IN FIREFOX

Not a really a Linux tip, but something I figured out how to fix. The
problem is that amazon audio clips redirect to a file named
"hurl.exe". Despite the extension this is a text file and is served
with a mime-type audio/x-pn-realaudio. The file contains the URL of
the actual realaudio sound file.

Unfortunately, this mime type isn't registered by the firefox
RealAudio plugin, and the fact that there's an .exe extension means
the option presented to uses is to save the file. The solution I've
found is to manually add the mime type to the mimeTypes.rdf file in
your firefox profile directory. You are then able to select a default
application to use the next time an attempt is made to open a file
with such a mime type is accessed.

I found that adding the following to mimeTypes.rdf did the trick:

  <RDF:Description RDF:about="urn:mimetype:audio/x-pn-realaudio"
                   NC:value="audio/x-pn-realaudio"
                   NC:editable="true">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:audio/x-pn-realaudio-plugin"/>
    <NC:handlerProp RDF:resource="urn:mimetype:handler:audio/x-pn-realaudio"/>
  </RDF:Description>

Not that I really understand it though...

----------------------------------------------------------------------
USEFUL IP ADDRESSES IN EVENT OF DNS FAILURE

micah.damtp.cam.ac.uk.  83807   IN      A       131.111.16.37
hermes.cam.ac.uk.       86400   IN      A       131.111.8.59
webserver.maths.nottingham.ac.uk. 3600 IN A     128.243.168.68 (www)
www.nottingham.ac.uk.   3600    IN      A       128.243.40.30
isa.nottingham.ac.uk.   3600    IN      A       128.243.42.27 (owa)
suiowa0.nottingham.ac.uk. 3600  IN      A       128.243.42.26 (imap4)

----------------------------------------------------------------------
CONVERTING EPS FILES TO BITMAP/RASTER FORMATS

By default ImageMagick seems to use fairly low resolution sampling,
which results in a small but low quality raster image. To increase the
resolution, use -density to set the sampling grid, For example:

  convert -density 800x600 -resize 800x600 bar.eps bar.tiff

----------------------------------------------------------------------
PREVENT EMACS FROM LOADING GLOBAL SETTINGS AFTER YOUR .EMACS FILE (2006-09-29)

With thanks to:
http://rura.org/blog/2004/10/26/emacs-require-final-newline-on-fedora-how-to-kill-it/

It seems that on some red-hat derived systems (including Fedora and
CentOS) emacs loads a global settings file at
/usr/share/emacs/site-lisp/default.el after the users .emacs
file. This fail contains the declaration:

  (setq require-final-newline 'ask)

which means every time you go to save a file which doesn't end in a new
line, you're asked if you want to add one. To disable this you can use
either

  (setq require-final-newline t)

to silently add a new line, or

  (setq require-final-newline nill)

to never add a new line, in your .emacs file. But then you need to
prevent the global file from being loaded by also adding:

  (setq inhibit-default-init t)

However, you may want to look at /usr/share/emacs/site-lisp/default.el
and copy any useful stuff from it (like wheel mouse scrolling) first.

----------------------------------------------------------------------
PRETTY PRINTING OF SOURCE FILES

Use a2ps with the -E (enable pretty printing) and -g (maximum effects)
options. 

----------------------------------------------------------------------
CONCATENATING / MERGING TWO OR MORE PDF FILES

Not sure how robust it is but 

  texexec --pdfarrange --noduplex --paper=A4 bar1.pdf bar2.pdf

just worked nicely on both things I tried. See also:
http://ansuz.sooke.bc.ca/software/pdf-append.php

Could also try PDFtk:
http://www.accesspdf.com/pdftk/

----------------------------------------------------------------------
PAPER SIZE CHANGED TO LETTER WITH PS2PDF

The script ps2pdf which converts postscript files to pdf, appears to
sometimes ignore the paper size of the underlying file and create a
PDF with the US Letter size. To fix this for A4 documents, use:

ps2pdf -sPAPERSIZE=a4 bar.ps

The papersize option is from ghostscript (see 'man gs' for
details). You can also set A4 as the default size by setting the
following environment variable:

GS_OPTIONS='-sPAPERSIZE=a4'

---------------------------------------------------------------------
REMOVING IMMEDIATE DUPLICATES FROM THE BASH HISTORY

add the following line to your .bash_profile file:

  export HISTCONTROL=ignoredups

For more details, search for HISTCONTROL in the bash man page.

Also of interest, is that you can use [ctrl]+r on the command line to
initiate a reverse interactive search (as in emacs) through your bash
history.

----------------------------------------------------------------------
FIX MAPLE 9.5 BROKEN WINDOW POSITIONING

At least under fvwm, at startup maple 9.5 positions its main window a
few pixels left and up from where it was last time. The inside corner
of the border and title bar appears to be placed where the outside top
left hand corner was before.

The following alias causes the initial placement of the window to be
in the top left of the screen.

  alias xmaple="perl -pi~ -e 's/MDIPosX.*$/MDIPosX=5/;s/MDIPosY.*$/MDIPosY=23/' ~/.maple9.5rc; xmaple95"

If you're using the single document interface, you will need to change
all occurrences MDI to SDI in the above.

----------------------------------------------------------------------
GLOBAL FIND AND REPLACE IN MULTIPLE FILES

To replace all occurrences of 'bar' with 'bar' in files matching *.txt,
use:

  perl -pi~ -e 's/bar/bar/g' *.txt

----------------------------------------------------------------------
UN-ROTATE AXIS LABELS IN GNUPLOT EPSLATEX TERMINAL

Unlike the pslatex terminal, there is no option not to rotate the
y-axis label with the epslatex output. Instead, the following Perl
one-liner can be used to remove all "\rotatebox" commands from the tex
file. Prefix with an exclamation mark to execute from within a gnuplot
source file:

  !perl -pi~ -e 's/\\rotatebox\{90\}//g' output.tex

----------------------------------------------------------------------
FIX BROKEN EPS FILES FROM GNUPLOT EPSLATEX TERMINAL

A bug in gnuplot 4.0 causes the eps files produced by the epslatex
terminal to star with "%%!" rather than the standard "%!". This causes
the file to print as text, rather than postscript, when sent to a
postscript printer. This can be fixed by the following Perl one-liner
inserted in a gnuplot script file:

  !perl -pi~ -e 's/\A%%!/%!/' output.eps

----------------------------------------------------------------------
ALTERING THE PAPER SIZE AND ORIENTATION IN XDVI

  xdvi -paper a4r bar.dvi

----------------------------------------------------------------------
EMACS SHORTCUT KEYS REFERENCE

Useful reference cards for Emacs and XEmacs can be found at:
http://www.refcards.com/

----------------------------------------------------------------------
PRINTING FROM EMACS WITH YOUR DEFAULT UNIX PRINTER

Add the following to your .emacs file, which will set the emacs
variable printer-name to the value of the $PRINTER environment
variable:

  (setq printer-name (getenv "PRINTER"))

----------------------------------------------------------------------
PRINTING MULTIPLE PAGES PER SHEET AND BOOKLETS

If necessary, you first need to create a postscript file of your
document.

Use 'psnup -n [input.ps] [output.ps]' where n is a power of two giving
the number of document pages per side of paper. Remember that for 2,
8, 32, etc pages per side, it will be landscape, so you'll need to
select 'short' if duplexing. For other options see the man
page. For example:

  psunp -2 -pa4 bar.ps | lpr -Ph1-short

If you want to make (say) an A5 booklet out of a ps file, with each A4
sheet of paper holding two A5 pages (four sides of the booklet) then
the pages will need reordering to be printed correctly. Use something
like

  psbook [input.ps] [output.ps]

Then, psnup -2 can be used to get the pairs of book pages on the
arranged on the physical A4 pages.

There is a more sophisticated command, pstops, which allows much more
control over positioning and zoom. For A4 LaTeX documents which have
large margins, it is often desirable not to shrink the text as much
when printing multiple pages per sheet. The following command is
appropriate for the margins on JFM papers:

  pstops '2:0L@.9(23.9cm,-1.9cm)+1L@.9(23.9cm,12.86cm)' in.ps out.ps

It can be combined with psbook and lpr using pipes in the usual way.

See also http://www.digitas.harvard.edu/~ken/psbind/ which may be able
to achieve similar results by automatically detecting the margins.

----------------------------------------------------------------------
COMBINING MULTIPLE POSTSCRIPT FILES INTO A SINGLE MULTI-PAGE DOCUMENT

The command psmerge is supposed to work for the case where the files
were created by the same program with the same settings (i.e. have the
same preamble). However, I couldn't get this to work when wanting to
merge several gnuplot graphs.

Instead, I manually cat'd the files together, then edited by hand with
emacs to remove the duplicated preambles, and add the correct page
numbers.

Each file was of the form:

  %!PS-Adobe-2.0
  %%Title: bar.ps

    [Prolog Stuff]

  %%EndProlog
  %%Page: 1 1

    [Document Stuff]

  end
  showpage
  %%Trailer
  %%DocumentFonts: Helvetica
  %%Pages: 1

It seemed to work by removing form the prolog stuff from all but the
first file, and removing from %%Trailer to the end from all but the
last file. Then the page numbers needed correcting, as did the total
page count on the last line.

----------------------------------------------------------------------
EDITING POSTSCRIPT FILES IN XFIG

  pstoedit -f fig input.ps output.fig

----------------------------------------------------------------------
EXTRACTING TEXT AND IMAGES FROM PDF FILES

  pdftotext

  pdfimages 

----------------------------------------------------------------------
CONVERTING .JPEG FILES TO .EPS WITHOUT UNCOMPRESSING

The jpeg2ps program adds an eps wrapper around a jpeg file to allow a
postscript interpreter to parse the existing jpeg data. This results
in much smaller files (typically only about a 20-30% increase on the
original jpeg).

See: http://www.pdflib.com/products/more/jpeg2ps.html for more
information and free download.

There's also a similar programme jpeg2eps written in postscript. It's
described at: http://rses.anu.edu.au/~andy/jpeg2eps/

----------------------------------------------------------------------
SETTING A LOCAL DIRECTORY FOR COMMON LATEX FILES

Add the following line to your .bash_profile file:

  export TEXINPUTS=".:~/texcommon//:"

where 'texcommon' is the name of the folder you wish to use.  The '.'
at the start ensures the folder from which you run latex is searched
first. '//' searches all sub-folders. The colons act as a
separators. Including ':' at the end, allows normal tex path to be
appended later.

With this setting, when looking for any input files and packages,
LaTeX will first search the current folder, then the '~/texcommon'
folder (and all its sub-folders), and finally the usual path defined
for your system.

The environment variables BIBINPUTS and BSTINPUTS work similarly to
define search paths for .bib and .bst files respectively.

----------------------------------------------------------------------
RELATIVE DIRECTORIES WHEN SPLITTING LATEX INPUT

The package import.sty allows files to be input from different
directories and further files referenced in input and includegradphics
commands are taken relative to the location of the file in which they
occur.

----------------------------------------------------------------------
INCLUDE REFERENCE NUMBERS FROM AN EXTERNAL LATEX FILE

  \usepackage{xr}
  \externaldocument[prefix]{filename}

----------------------------------------------------------------------
CAPTURE SOME OR ALL OF THE X11 DISPLAY AND WRITE TO AN IMAGE FILE

You can use the import command from ImageMagick. The simplest thing
to type is:

  import bar.png

and then drag out a rectangle on the screen. The file extension (where
recognised) will determine the appropriate output format.

See `man import' for details, and other variants.

----------------------------------------------------------------------
MAKING OHP SLIDES / PDF PRESENTATION WITH LATEX

I've used the foilTeX package, which is available on the DAMTP
system. However, if the DAMTP version is out of date it may contain a
couple of annoying features (e.g. dvi/ps rotation problem) which can be
fixed if you get the latest version. e.g. download the class files to
you common latex directory (see above).

----------------------------------------------------------------------
COLOURS, IMAGES, ROTATING, AND SCALING WITH LATEX

All these can be accomplished using packages from the graphics bundle,
which is usually already installed by default. You just need to have
the relevant \usepackage{} statement in your preamble to enable the
commands you wish to use. Links to documentation and the installation
files can be found here:

http://www.ctan.org/tex-archive/help/Catalogue/entries/grfguide.html

Or the UK mirror:

http://www.tex.ac.uk/tex-archive/help/Catalogue/entries/grfguide.html

----------------------------------------------------------------------
USING LaTeX TO GENERATE PDFs AND DVIs FROM THE SAME DOCUMENT

If you're working on a LaTeX document which needs to be passed through
LaTeX and pdfLaTeX, you can save having to continuously change between
using the dvips and pdftex driver options using something like this:

  \ifx\pdfoutput\undefined
    \documentclass[...,dvips]{...}
  \else
    \documentclass[...,pdftex]{...}
  \fi

If images are included without the extension to their name, then the
pdfLaTex and LaTeX will (if setup well) look for appropriate
extensions (eg .eps for LaTeX, and .pdf .png .jpg for pdfLaTeX). You
will of course need to provide all your images in two different
formats.

You can add \usepackage{epstopdf} to your preamble which will
automatically create pdf version of any pdf-less eps files when
pdfletex is run. However, better results will probably be obtained by
generating a pdf directly from the image/diagram source where
possible.

----------------------------------------------------------------------
COMPRESSING LARGE EPS FILES FOR USE WITH LATEX

from http://www.dd.chalmers.se/latex/tips_e.html

If you have a large picture that takes up a lot of space on your
account, you can compress it using gzip and then include it in your
document.

If you have a picture called pic.eps, you proceed like this: Copy the
row in pic.eps that begins with %%BoundingBox to a new file called
pic.eps.bb. Then compress the picture using the gzip command: `gzip
pic.eps' Include the picture in your LATEX document like this:

  \begin{figure}[!ht]
  \centering
  \includegraphics[width=10cm]{pic.eps.gz}
  \caption{A compressed picture.}
  \end{figure}

You may also be able to get away with omitting the .eps.gz from the
filename. This can be useful if you also have a png/jpg/pdf version
(with the same filename stem) for use with pdfLaTeX. LaTeX / pdfLaTeX
should be able to choose the appropriate format.

----------------------------------------------------------------------
TO DISPLAY THE LABELS USED IN A LATEX FILE IN THE OUTPUT

Try adding one of

  \usepackage{showlabels}
  \usepackage{showkeys}

to the preamble. The former just prints the label names in the margin
when they're defined. The latter also prints them in the text when
they're referenced, though this can be disabled with something like:
  
  \usepackage[notref,notcite]{showkeys}

----------------------------------------------------------------------
OTHER POTENTIALLY USEFUL LATEX PACKAGES TO INVESTIGATE

dropcaps.sty dropping.sty for drop caps

floatflt.sty  wrapfigure.sty for text-wrapped figures and
tables (Also floatfig, a deprecated version of floatflt).

appendix.sty for allowing sub-appendices within chapters (or sections)

----------------------------------------------------------------------
START PINE WITH A DIFFERENT INBOX

  pine -inbox-path=/home/MAIL/$USER

To do this every time, you can either set up a bash alias, or alter
your .pinerc file.

----------------------------------------------------------------------