Friday, September 6, 2013

Something about LaTeX...

Currently I am writing a paper in LaTeX, using Eclipse as an editor and jura as the document type. The paper is restricted to 20 pages, and both the page format and the tracking, as well as the line spacing, are defined and cannot be played with.

I spent some time fiddling with the jura files to get more space, and I came across some interesting possibilities (at least I think they are). As I found nothing on them on the internet I thought I'd share it with you, even though this might be very specific to the _old_ jura package which still had the alphanum.sty file (just found out that there is a newer version of the jura package which even has comments, the alphanum.sty is included in the jura file - you can obtain it here - the regular jura package is part of the texlive and miktex distributions).

As a result of my research, I found out how to achieve so called runin headings:

old:
A.I.1.b. This heading likes to stay in the text
and this is the content. It used to start only in the next line.


new:

A.I.1.b. This heading likes to stay in the text     and this is the content, starting right after the heading.  

One might ask why one might want to use it like this when there is a way to skip the text of the heading and just use the numbers. But sometimes, papers tend to get complicated, especially when you are forced to take out free lines - it just gets messy. So, a little structure can be created by including heading texts. This is what I think :-D

- Accessing the critical files, alphanum.sty and jura.cls, in the first place
- Editing the short heading format (toc* and sub*)
- Adjusting the space before and after the headings.
- Getting the text to be in line with the long heading


Accessing the files

For all of the other tasks we'll need to edit the alphanum.sty file. Find out where your alphanum.sty file is located by checking out your LaTeX log file, it should point you to the correct directory.

This goes for all of you: Create a backup of the file. Open it with your normal user through your file browser, copy the contents to a new editor window, save it somewhere.

 ... on Linux:

Using texlive on Ubuntu 12.04, you'll probably find it in something like /usr/local/texlive/2012/texmf-dist/tex/latex/jura/alphanum.sty. Remember, to edit it you'll need sudo, your normal user will be able to view it, but cannot edit it.

For GUI users: If you don't know how to handle this -

Open the file in an editor with sudo rights. To do this...
    1. Press ctrl+alt+t - a terminal window should open
    2. Type sudo gedit <path to your file> and hit enter
      (you could use any other editor as well)
    3. You'll be asked to enter your password. Type in your password, don't be confused - you won't see any characters or asterisks while typing. Hit enter
    4. A new text editor window will open. Do not close the terminal. 

... on Mac:

I won't explain this in detail, if you want to know, just leave a comment. It is similar to Linux, probably a different editor. I simply used vi to edit the file.Thus, in a terminal window, enter sudo vi <path to your file> and enter your password.

... on Windows: 

Open the command line as an administrator user. To do this, search for cmd and either hit  ctrl+shift+enter or perform a right click on the menu entry and select "Run as administrator". Confirm the request to run it as an admin. 
I am not very used to using the Windows cmd, but this worked for me - just enter the path to your file. In my case, this was C:\Program Files\MiKTeX 2.9\tex\latex\jura\alphanum.sty. You can use tab to autocomplete the path. Once you entered the path, just hit enter. Windows should open the default editor. 

Editing the short heading format (toc*{} and sub*{})

The jura package provides a short heading format, which will only display the heading number in the main matter, the full heading will be in the table of contents. I found this pretty convenient as it saves a lot of characters. But by default, the numbers are pure text, and I wanted them to at least be bold, so that they can be spotted easily. To achieve this I added \textbf or \bfseries to every heading in my first paper, because I did not know how to edit all of the entries at once. 

But now we found our config files - alphanum.sty! This is where all the magic happens. So, open the file as explained above, and look for a line that says \newcommand*{\J@ShortToc}[1]{\stepcounter{lvl\alph{tiefe}}\J@Number. To get a bold faced heading number for the short format, just add \textbf{} around the number - the line should now look like this: 
\newcommand*{\J@ShortToc}[1]{\stepcounter{lvl\alph{tiefe}}\textbf{\J@Number} 

 Save and enjoy.

Adjusting the space before and after the long headings

By default, long headings leave quite some space before and after them. Not good for papers with a page restriction... But this can be fixed. Open the alphanum.sty again and look for this block of code:

\newcommand*{\J@LongToc}[2][]{%
\@startsection{lvl\alph{tiefe}}{\value{tiefe}}{0pt}
{\ifnum\value{tiefe}=1 -4ex plus-1,5ex minus-0,ex\else
-2,7ex plus-0,8ex minus-0,2ex\fi}
{\ifnum\value{tiefe}>7 -1em plus-0,5em\relax\else
0,6ex plus0,3ex minus0,1ex\fi}


"Tiefe" refers to the level of the heading, thus tiefe = 1 means the first heading level. Tiefe > 7 means all heading levels higher than seven. -4ex or -2,7ex seems to be the space before the heading. Set it to zero if you like - just play around with the numbers until your file looks as you please. 


"Inline" or "runin" headings

In my current paper, I decided not to use the short heading because I did not want to put in any blank lines between the paragraphs, thus the text would not look very structured. I am using the long headings now. But the long headings have a linebreak by default - so the text after the heading will start in a new line. What an aweful waste... Just find the above mentioned paragraph again and have a look at my changes - I adjusted this paragraph (i. e. played with the numbers):

\newcommand*{\J@LongToc}[2][]{%
\@startsection{lvl\alph{tiefe}}{\value{tiefe}}{0pt}

{\ifnum\value{tiefe}=1 -4ex plus-1,5ex minus-0,ex\else-0,7ex plus-0,5em minus-0,2ex\relax\fi}
{\ifnum\value{tiefe}>7 -1em plus-0,5em\relax\else -1em plus-0,5em\relax\fi}



If you feel like now it looks too tight, note that there are ways to insert space between headings you want to make look special - try \medskip or \smallskip in your .tex file (insert it before the heading).
Again, if you have any questions, just leave a comment. Hope this helped at least some of you.