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.

Tuesday, March 26, 2013

Joomla! 2.5 / Apache: File Downloads, docx etc.

I let my users upload files and link to them in their articles. As I want to force them to download the files directly (and don't want them to view it in the browser), I am using a file called download.php which I include in the URLs.

Thus, instead of "/myfolder/myfiles/myfile.pdf" the href attribute of the link will be like "download.php?filename=/myfolder/myfiles/myfile.pdf".

In download.php I declare headers and do some things about the filename. It was always working fine for pdf or doc files, but there seemed to be something wrong with the "new" file formats of Office (docx, ppsx etc.) - if a user clicked on that file, it would be downloaded, but could not be opened (the message said something like "cannot read file"). A comparison of the original file and the downloaded file showed no difference except for one character which was not even visible. Fun fact: OpenOffice could open the file without any problems... Lots of pages suggested to check the MIME type configuration of apache in /etc/mime.types, but the docx formats were already there.

I did a lot of research and came across a post on http://php.net/manual/de/function.header.php by eonrglez at gmail dot com.

I included all the header information suggested in this post (except for the file size), from Pragma to Content-Transfer-Encoding, and voilĂ  - it works.

Thursday, March 21, 2013

Joomla! 2.5: Finally - A Soulution For Applying Changes (Front End Editing)

This is about (front end) creating / editing an article.

I have been looking for a way to save (apply changes) in Joomla's front end for a really long time. What I needed was just a button which would let me save changes without redirecting somewhere else...

Recently I came across this page.

I applied all suggested changes to my page, and it works! On the downside you need to edit Joomla core files, and the changes made to them will probably be lost after the next update...

Tuesday, March 19, 2013

Joomla! 2.5: Another LDAP (?) Issue

This one was really driving me crazy. Really.

But we can't blame LDAP for that, at least I don't think so...


We have a LDAP authentication set up which is working really well. Except when a user enters a wrong password - then he just gets a blank page. The same is the case for articles with a user restriction (user need to be logged in to view the article) - again, just a blank page.

Turns out the blank page is not as blank as it seems - the source is there, including a nice error message. And a line somewhere in the head saying

html{display:none;}

A lot of research took me to this page, and I decided to try the following, out of some instinct:

"Comment out line 823 (or thereabouts) in:
libraries> joomla > html > html> behavior.php
$document->addStyleDeclaration('html { display:none }');
To comment out, just add 2 slashes "//" in front of the line."


Works like a charm. I am afraid the change will be undone by the next Joomla update, but I'll try to report a bug. In the meantime I hope this helps. Happy coding!

edit: Someone reported a bug on a similar problem, seems like version 2.5.9 will not have this line any more. See here.

Wednesday, February 20, 2013

Recover Joomla PhpMyAdmin MySQL Database

This morning I found myself confronted with a new problem:

Our server crashed, we had to set it up again - from scratch. Fortunately, we did have some backups - the Joomla! files, and the mysql folder (on Linux: /var/lib/mysql).

(We are using a Linux server with mysql and phpmyadmin.)

I then tried to recover our database. What I thought: Just copy the contents from the database backup folder (mysql/joomla) to the mysql folder on the server and everything should be fine. That was what they said on the internet, too. Turns out there were only .frm files in that folder, no .myd etc. Turns out that .frm only contains the table structure. But where is my data?

Everything's not lost.

I found a huge file in the mysql backup folder, called ibdata1.

So what you need to do now is (instructions are for Linux):

- Stop your mysql service
  sudo stop mysql
- Copy that ibdata1 file to the /var/lib/mysql folder (consider making a backup of the existing ibdata1 file)
  cd /var/lib/mysql
  sudo mv ibdata1 ibdata1backup
  sudo cp <backupfolder>/ibdata1 /var/lib/mysql
- check that permissions are set to mysql as owner and group
- restart mysql service
  sudo start mysql
- if you set up any new passwords, check that Joomla! has the correct password in its configuration.php file for mysql.