Notes

run

LaTeX

How to use cleveref and amsthm in such a way that it works.

It took me a long time to find out how to use cleveref and amsthm together. If you have texdoc installed, you can find pretty much the same info in the documentation for cleveref. First off, you'll need the package aliascnt. Then you use an alias for the thm counter (or whatever you're using). An example follows:

\usepackage{amsthm}
\usepackage{aliascnt}
\usepackage{cleveref}

\newtheorem{thm}{Theorem}[section]
\crefname{thm}{theorem}{theorems}
\Crefname{thm}{Theorem}{Theorems}

\newaliascnt{lemma}{thm}
\newtheorem{lemma}[lemma]{Lemma}
\aliascntresetthe{lemma}

\newaliascnt{prop}{thm}
\newtheorem{prop}[prop]{Proposition}
\aliascntresetthe{prop}
\crefname{prop}{proposition}{propositions}
\Crefname{prop}{Proposition}{Propositions}
To test the thing out, try it with this.
\begin{thm} \label{1}
A very important statement.
\end{thm}
\begin{lemma} \label{2}
A less important statement.
\end{lemma}
\begin{prop} \label{3}
$1=0$.
\end{prop}

\cref{1} \Cref{1}\\
\cref{2} \Cref{2}\\
\cref{3} \Cref{3}

How to use xfig in such a way that it works for both dvi and pdf.

Here, I explain how to incorporate pictures created using xfig into a LaTeX document. More instructions can be found here.

If you want both pdf and dvi coming from the same document, then the packages ifpdf and ifthen are pretty useful:

\usepackage{ifpdf}
\usepackage{ifthen}
Next you'll need some graphic packages:
\ifpdf
\usepackage[pdftex]{graphicx,color}
\else
\usepackage{graphicx}
\fi
Now, draw your favorite graph of whatever using xfig and export as Combined PS/LaTeX (both parts) as well as Combined PDF/LaTeX (both parts). This produces a bunch of files, all of which are best kept in the folder containing the .tex document (or wherever else you prefer). Now you can define a handy command
\newcommand{\mynd}[4]
{
    \begin{figure}[#2]
    \begin{center}
        \ifpdf
            \input{#1.pdf_t}
        \else
            \input{#1.pstex_t}
        \fi
        \ifthenelse{\equal{#3}{}}
        {
        }
        {
            \caption{#3\label{#4}}
        }
    \end{center}
    \end{figure}
}
This way, you can import a picture into a latex document which works for both latex and pdflatex. It takes four arguments, these are: #1 the name of the xfig file with no extension; #2 any of the letters h, t, b, etc for your preference of setting the picture here, top, bottom, etc; #3 the caption of the figure—if left empty there will be no caption and no label; #4 the label identifying the picture. For correct configuration of xfig, see section below.

To automate the task of exporting the files as above, make sure that transfig is properly installed (this provides fig2dev) and keep the following script handy.

for i in *.fig
do
  j=`echo $i | sed s/.fig$//`

  if [ -e $j.pstex_t ]
  then
    echo "Overwriting $j.pstex_t"
  else
    echo "Creating $j.pstex_t"
  fi

  echo "\begin{picture}(0,0)%"        >  $j.pstex_t
  echo "\includegraphics{$j.pstex}%"  >> $j.pstex_t
  echo "\end{picture}%"               >> $j.pstex_t
  fig2dev -L pstex_t $j.fig           >> $j.pstex_t

  if [ -e $j.pdf_t ]
  then
    echo "Overwriting $j.pdf_t"
  else
    echo "Creating $j.pdf_t"
  fi

  echo "\begin{picture}(0,0)%"        >  $j.pdf_t
  echo "\includegraphics{$j.pdf}%"    >> $j.pdf_t
  echo "\end{picture}%"               >> $j.pdf_t
  fig2dev -L pstex_t $j.fig           >> $j.pdf_t

  if [ -e $j.pstex ]
  then
    echo "Overwriting $j.pstex"
  else
    echo "Creating $j.pstex"
  fi

  fig2dev -L pstex   $j.fig > $j.pstex

  if [ -e $j.pdf ]
  then
    echo "Overwriting $j.pdf"
  else
    echo "Creating $j.pdf"
  fi

  fig2dev -L pdftex  $j.fig > $j.pdf

done

It can also happen that this stuff doesn't compile into dvi if some text has some color. Typically, the text has color 'black', and manually changing everything to the color 'default' makes it work. However, this is a super boring way of solving a problem, when the following command will do the job:

for i in *.pstex_t; do cat $i | sed  s/.color.rgb..0,0,0.// > $i.old; mv $i.old $i; done

Lists and indentation

The following defines an environment for lists where the numbers and the content all line up nicely with the rest of the material. This is especially convenient to list out examples or remarks, where each element of the list is typically a full paragraph, rather than just a word or two.

\newenvironment{blist}
{
  \begin{list}{(\thedummy)}
  {
	\setlength\labelsep{4pt}
	\setlength\itemindent{4pt}
	\setlength\leftmargin{0pt}
	\setlength\labelwidth{0pt}
	\setlength\parsep{0pt}
    \usecounter{dummy}
  }
}
{
  \end{list}
}
The number 4 here can be adjusted, but to me it seems to produce reasonable space. With the above code in the preamble, you can now create a nice list like this:
\begin{blist}

\item
The first example is about something.

\item
The second remark is quite important.

\end{blist}
For further info, see e.g. 3.4.4 of The LaTeX Companion, Second Edition.

Ending a proof in displaymath

If you end a proof with a formula in displaymath, then the qed symbol will go to the right in a new line after the formula, which creates a big ugly white empty space in your document. And if you just put a \qedhere inside displaymath, then the qed symbol will not get pushed to the right. What to do, right? Fortunately, some good person at stackexchange gave a solution to this. I don't know how this works, or what's happening in this black box (pun intended), but the outcome is all that matters.

\[
\pushQED{\qed}
  \fa{\gamma\in\partial\triangle^{(1)}}
     {\wt_\gamma g \geq m_\gamma + 1}.
\qedhere
\popQED
\]

Change heading of references

Add the line
\renewcommand*{\refname}{}
to the preamble to get rid of the title of the bibliography, which defaults to References. Alternatively, you can put in whatever you want there. This is useful, for e.g. a list of publication, where you just want to print the list of references.

Vim

Some macros

I keep a macro in the l register for compiling latex documents. This requires latexmk. For this, execute

let @l=":w\n:!if echo % | grep tex; then latexmk -pdf --synctex=1 %; fi\n"
or, if you're using (t)csh,
let @l=":w\n:!if ( % =~ *.tex) latexmk %\n"
This one I keep in @e to toggle spelling.
let @e=":set spell! spelllang=en\n"
It is also useful to toggle autoindent as follows:
let @i=":set invautoindent\n:set autoindent?\n"

Colors

So far, I like the color scheme vividchalk. For this to work, copy the file vividchalk.vim to ~/.vim/colors/ and add the lines

syntax enable
colorscheme vividchalk
to your .vimrc. Don't forget to use a slick font.

Looking for nonascii characters

To search for any nonascii character, just use

/[^\x00-\x7F]
as suggested by this stackowerflow post.

Search and replace with multiples

The following command replaces any integer with its multiple with four.

:s/\d\+/\=submatch(0)*4/g
The expression \d\+ matches any string of digits. In the second part, the \= indicates that the string is an expression which should be interpreted. The submatch(0) gives the matched pattern, in our case a string of digits. This is then quadrupled by *4. If you need to multiply numbers inside some pattern, you can flag the number and use submatch(n), where the number is the nth flagged part. As an example, running
:s/\(\d\+\) monkey[s]*/\=submatch(1)*4 . " monkeys "/g
will turn the string
1 monkey and 4 cats and another 8 monkeys
into
4 monkeys  and 4 cats and another 32 monkeys

Autocompletion

I didn't sign up for an account at superuser.com just to upvote the very helpful answer to this post, but user138727 sure did. Put

set wildmode=list:longest
into your .vimrc, and vim will from now on do autocompletion the right way.

Tabs

If you don't like tabs, use
set expandtab
set tabstop=4

Merging lines of a paragraph

The command

:%g/./.,/^$/-j
merges the lines of each paragraph into a single line. This assumes that paragraphs are separated by empty lines.

Latex-Suite

The Latex-Suite comes with some pretty neat tools, in particular, sensible folding rules. I don't like their macros, though, so keep this line in your .vimrc
let g:Imap_FreezeImap=1
Also, the following is good
let g:Tex_FoldedEnvironments="verbatim,comment,eq,gather,align,figure,table,
\thebibliography,keywords,abstract,titlepage,lemma,definition,def,thm,
\theorem,prop,block,rem,proof"
Thanks go to Stackoverflow for educating the populus on how to continue new lines in vim scripts. Apparently, one must also include these
filetype plugin on
set grepprg=grep\ -nH\ $*
let g:tex_flavor='latex'

Automatically set tw for composing email in mutt.

Add the following line to .vimrc to set the text width to 72, whenever editing an email (change the directory and format according to your system)

au BufRead /tmp/mutt-* set tw=72
This gem, like so many others, was found on the Arch Linux wiki.

.Xdefaults / .Xresources

XDvi

Some of these parameters should obviously be adjusted to the dimensions of your screen.

XDvi*expertMode:    0
XDvi*noInitFile:    1
XDvi*highlight:     black
XDvi*foreground:    black
XDvi*geometry:      1023x1080
XDvi*shrinkFactor:  5
XDvi*topMargin:     5cm
XDvi.mainTranslations: #override   \
<Key>G:   goto-page(1)          \n \
<Key>.:   forward-page()        \n \
",":      back-page()           \n \
<Key>j:   down(0.015)           \n \
<Key>k:   up(0.015)             \n \
<Key>h:   left(0.015)           \n \
<Key>l:   right(0.015)          \n \
<Key>i:   set-shrink-factor(+)  \n \
<Key>u:   set-shrink-factor(-)  \n \

XFig

If you don't put in these options, an error will come your way. The special flag is important if you want text to be interpreted as LaTeX code. In this case, remember to export everything to Combined PS/LaTeX (both parts) for dvi output and Combined PDF/LaTeX (both parts) for pdf output. Better yet, use the script above to automate this.

Fig.latexfonts:       true
Fig.specialtext:      true
Fig.inches:           false
Fig.startgridmode:    1
Fig.startposnmode:    1
Fig.zoom:             3.0
I always have to say explicitly that the color of text should be default rather than black. Otherwise the LaTeX compiler spits out an error and halts. If you find a way to do this automatically, please let me know.

XDaliClock

For optimal desktop clock experience, use xdaliclock with the following parameters:

XDaliClock.mode:         24
XDaliClock.seconds:      false
XDaliClock.cycle:        false
XDaliClock.transparent:  true
If you're using evilwm, use the command line parameters -app xdaliclock/XDaliClock -g 444x162+a+b, where a,b is your favorite position on the desktop for a clock.

Miscellaneous

Fonts

Say you have a directory /full/path/to/dir/ full of your favorite fonts. How can you use them in your favorite applications? Use the program mkfontdir to create a file fonts.dir. Then use xset to tell the system to use this directory. In short,

cd /full/path/to/dir/
mkfontdir
xset +fp /full/path/to/dir/
The last of these commands must be repeated every time you log in using xdm, startx or xinit or something like that. Therefore, it is good to add it to .xsession if you use xdm or startx, or to or .xinitrc if you use xinit. An excellent font for the command line is terminus.

Bash

If you don't want bash to spam you with advertisements for packages when you mistype a command, put this into your .bashrc.

command_not_found_handle() {
    printf "%s: command not found\n" "$1" >&2
    return 127
}

Mutt

Mutt is the best email client in the world. Its only downside is that its documentation—excellent as it may be—is something of a jungle. To make things simpler for anyone interested in starting using this great program, I have made my configuration files publicly available here. To get started, just follow the instructions in the README.

Don't forget to install abook. It should be available in most package systems and works pretty much out of the box.

If you're interested in using encryption, have a look at these instructions. The text may look daunting at first, but it is very much to the point and gives a practical guide to GnuPG, with emphasis on mutt. The file crypto from the above git repository has pretty much been copied directly from this manual.

To open html emails, add the following lines to your .mailcap

text/html; firefox %s &; test=test -n "$DISPLAY"; needsterminal;
text/html; w3m -I %{charset} -T text/html; copiousoutput;
Also, make sure to have w3m installed. This way, the hypertext will appear formatted in the pager, and you can also view it in firefox by pressing v and selecting the file. I found these lines at http://jasonwryan.com/blog/2012/05/12/mutt/ and modified them to use firefox.

*Shameless plug*—if a text based interface to email is not your cup of tea, then check out mailpile. It's an effort to make encrypted email easy and appealing, rather than having to jump through hoops like a dog. Keep in mind, though, that mailpile is still in beta stage.

Synctex with vim and zathura

Synctex is a pretty cool thing. There seem to be a lot of super complicated explanations online on how to get it to work with vim and zathura. The latex-suite even gets dragged into the whole business. Here is a simple setup which allows you to do forward search. I'll update this once I figure out how to do backwards search in a simple way.

Assume that you have a document proj.tex. First step is to compile it, producing a .pdf file and a .synctex.gz file. This is achieved by running
latexmk -pdf --synctex=1 proj.tex
in the directory containing the source file. Above, you can find a macro which automates this from vim. Open the .pdf document by running
zathura proj.pdf
as usual. To make the viewer go to the place corresponding to line 500 in the source code, all you need to do is run
zathura proj.pdf --synctex-forward=500:1:proj.tex
To wrap the whole thing up into a neat macro, keep the following in your .vimrc
let @f=":exe \"!zathura `echo % | sed s/tex$/pdf/` --synctex-forward=\"
\ . line(\".\") . \":\" . col(\".\") . \":\" . \"%\"\n\n"

Printing text

In order to print a unicode text file, it's not good just to feed it to the printer. Better use paps, a small program which outputs a perfectly usable Postscript document, which then can be sent to the printer.

Dotfiles

Abook

Here is my ~/.abook/abookrc

set index_format=" {name:39} {email:39} "
set show_all_emails=true
set sort_field=Name

Zathura

Zathura is a choice application for viewing pdf and djvu documents. What follows is my configuration file, found in ~/.config/zathura/zathurarc

set font "Terminus normal 8"
set inputbar-bg black
set inputbar-fg white

set first-page-column 2

set guioptions ""

map . navigate next
map , navigate previous

map C-u navigate half-up
map C-d navigate half-down
map C-e navigate up
map C-y navigate down

map i zoom in
map u zoom out
The binding of . and , is inspired by the default bindings of the nice pdf viewer mupdf.

Music On Console

The best music player is music on cosole. The configuration file for mocp is usually ~/.moc/config. For me, this looks like

Theme = moca_theme_ed
Keymap = keymap

Layout1 = directory(0,0,100%,100%):playlist(0,0,100%,100%)
Layout2 = directory(0,0,50%,100%):playlist(50%,0,FILL,100%)
The first line selects a theme. I made small modifications to the theme moca_theme which I keep in ~/.moc/themes/moca_theme_ed and reads
background              = white         black
frame                   = white         black

window_title            = yellow        black   bold
directory               = white         black
selected_directory      = yellow        black   bold

playlist                = white         black
selected_playlist       = yellow        black   bold

file                    = white         black
selected_file           = yellow        black   bold
marked_file             = green         black   bold
marked_selected_file    = green         black   bold

info                    = magenta       black   bold
selected_info           = yellow        black   bold
marked_info             = green         black   bold
marked_selected_info    = yellow        black   bold

status                  = red           black   bold
title                   = yellow        black   bold
state                   = red           black   bold

current_time            = magenta       black   bold
time_left               = green         black   bold
total_time              = magenta       black   bold
time_total_frames       = magenta       black   bold

sound_parameters        = white         black   bold
legend                  = white         black
        
disabled                = red           black   bold
enabled                 = green         black   bold

empty_mixer_bar         = green         magenta 
filled_mixer_bar        = magenta       green
empty_time_bar          = green         magenta
filled_time_bar         = magenta       green
entry                   = white         black
entry_title             = magenta       black   bold
error                   = red           black   bold
message                 = green         black   bold
plist_time              = red           black   bold
Note the options selected_info, marked_info and marked_selected_info which seem to be missing from many of the themes provided with the program. The second line instructs mocp to read the file ~/.moc/keymap and use the keybindings there. For me, this reads simply as as
menu_down += j
menu_up += k
The last two lines switch the two default layouts, as I prefer to just use the file browser.

ncmpcpp bindings

ncmpcpp has a nice interface, but with the default setup, nothing happens if you press the spacebar or the vi navigation keys. This flaw can be remedied by setting up a file .ncmpcpp/bindings with the following content:
def_key "j"
  scroll_down
def_key "k"
  scroll_up

def_key "h"
  volume_down

def_key "l"
  volume_up

def_key "space"
  pause

Sagemath

If you're using a dark terminal, then use the following line

%colors Linux
in the file $DOT_SAGE/ipython-X.Y.Z/profile_default/startup/50-color.ipy. This tip, and more, can be found here.
Or add it to ~/.sage/init.sage.

GP/PARI

It is convenient to keep the following in .gprc, if you use a dark background for your terminal:

colors = "darkbg"