Archive | LaTeX RSS for this section

$$ math $$ versus \[ math \] in LaTeX

Let’s say you want to display some maths in LaTeX. You don’t want to use equation and related environments.

Inline maths is enclosed between dollar signs, and is formatted as part of the sentence.

A displayed equation is enclosed between pairs of dollars or between \[ and \]. But $$ … $$ and \[ … \] are not the same. For one thing, \[ … \] responds to the documentclass option fleqn to align the equations to the left rather than center them. Thus, we get this:

Where ‘Inline’ is indented because it starts a paragraph. First two displayed equations use $$ … $$ and are centred, the last uses \[ … \] and is indented by a length called mathindent.

Here is the LaTeX code

Inline maths: a simple equation might be $x+y=1$.
The solutions to the quadratic equation
$$ax^2 + bx + c = 0$$
are given by
$$x=\frac{-b \pm \sqrt{b^2-4ac}}{2a},$$
which is to say
\[x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}.\]

Notice the argument ‘fleqn’ has been given to the article class, but $$ … $$ did not obey it. \[ … \] did, but not all the way to the left. If you want the left aligned maths to be hard left, you need to redefine mathindent to be zero length:


and this gives




Non-breaking en rule (en dash) in Microsoft Word… not really.

Say you’ve got a number range. The proper way to format that is with an en rule (en dash), so it looks something like ‘4­–5’ whereas a hyphen would look like ‘4-5’. Now, you probably don’t want the number range to break across lines. That’s fine with a hyphen, since Ctrl-Shift-Hyphen gives a non-breaking hyphen (in Word). But you don’t want a hyphen you want an en rule. One option is to put in a non-breaking hyphen then make it twice as wide.

  • Highlight the non-breaking hyphen (and the hyphen alone, not any trailing/leading characters or spaces).
  • Right click on the hyphen and select the ‘Font…’ menu, then ‘Advanced’ (rule #1 in Microsoft products: Just about anything worth doing is considered ‘Advanced’).
  • Change the number in the ‘Scale’ box to be about 200%.
  • Exit from the menus.
  • Type an en rule in your document, alongside the stretched hyphen. (Ctrl-Keypad Minus.)
  • Compare.
  • Swear.
  • Use it anyway since it’s the most reasonable alternative. You may want to adjust the height; but will this highly manual fix work if font is then changed? No.
  • Watch while Word mysteriously moves the instruction to widen the characters to random places in the document so you end up with double width text in unexpected places.
  • Swear.
  • Learn LaTeX where all you need to type is \mbox{4–5}.
Dialog box in Microsoft Word for changing character size, position and spacing.

Stretch out the hyphen (or anything else) using the ‘Scale’ box. Gives fixed selections but can type in other values. Something between 175% and 225% usually works. Note: Can also be used to adjust the position if need be.

I have tried putting text in boxes, but the baseline is not maintained – it sits high. Character positions can be adjusted down, but then Word boxes clip the contents. Perhaps there is a better solution? I tried making it an equation, or using a minus character, but neither was really satisfactory. I’d like to hear about a better answer because, sadly, using LaTeX is not always viable.

Non-bresaking en rule in Word; results of stretching a hyphen.

Non-breaking en rule in Word; results of stretching a hyphen.

My Word.

My new work profile.

I am now officially an editor… From the company website:

A grab from the Biotext website, as it was in May 2017.

A grab from the Biotext website, as it was in May 2017.

Further updates as they come to hand…

The Sharp MZ-721 font in a terminal emulator

Long ago I made a LaTeX font out of the character glyphs from the Sharp MZ-721 8-bit microcomputer. Then I made a font for use in a terminal emulator. How did I do it? From the below, I seem to have used the pk file generated when the font was used in LaTeX, then realised I could go direct from the original Sharp character ROM. I made a bdf file, which is an old but usable format. You can download it from here, and the crap below will help you install it if you need help. But you can google ‘installing bdf fonts’ and get something more useful. And edit the fonts to make them better. Or not,. whatever.

I don’t remember any details. Here is the contents of a ‘note to self’ file I wrote at the time…


Installed gbdfed for AMD64 by downloading the following package:

Package: gbdfed (1.5-1.1)

squeeze (oldoldstable) (x11): X11 font editor 1.5-1.1: amd64 armel i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 sparc


$ sudo dpkg -i gbdfed_1.5-1.1_amd64.deb

and it seems to work. Opened the pk file for the first MZ font and then saved as bdf. That is all so far.

How to use a BDF font file…

move it to

$ cd .fonts
$ mkfontdir
$ cd mz
$ mkfontdir
$ chmod 644 *
$ xset fp+ $HOME/.fonts/mz
$ xset fp rehash

If I go to the.fonts/mz and type

xterm -fn -unknown-mz7cgint-medium-r-normal–83-100-600-600-p-530-fontspecific-0

it works but the font is enormous, since it is just mapped directly as
a 600x600 bitmap.  Needs to be resized... look at gbdfed again

OK, changed font ascent, x-ren and y-resn in properties to 24 instead of 600.

No diff.  Set point size to 12.

OK, use xfontsel to get an idea of sensible parameters.

Still too big --- maybe go back to metafont and try as low res device:
$ mf '\mode=epsfast; input MZ7CGint'

$ gftopk  MZ7CGint.60gf

open and save with no modifications. Move it to… ~/.fonts/mz/MZ7CGint.bdf


$ mkfontdir
$ xset fp rehash
$ cat fonts.dir
$ xterm -fn -unknown-mz7cgint-medium-r-normal--10-100-60-72-p-60-fontspecific-0

and all good. Note that I had to delete all coloured pixels in char20 (hex) since it was filling up the screen with triangles. Note also that this mode proved a bit small… went and had another look at and picked a mode a bit bigger, say about 100dpi…

$ mf '\mode=nextscrn; input MZ7CGint'

works pretty well. Font could do with some more leading. Play in font editor…
Problem is that we have an 8×8 font in a number of boxes that is not a multiple of 8. What other modes are there…

96 dpi? (atarins) — odd choices of blackened pixels.
120 (onetz)? — odd choices of blackened pixels.
120×144 (epswlo) — odd choices of blackened pixels.
144dpi lasf — odd choices of blackened pixels.
72×120 is epsdrft — nope
laserjet 300 dpi — nope
hifax 200dpi — looks great, but will font be huge?

Yes, it looks huge but works really well. Now, can we downsize it?

Now, fontforge can open the bdf file… That means one can make a PostScript font or similar… (maybe one day…)

$ sudo apt-get install bdfresize

$ bdfresize -f1/2 MZ7CGint.bdf > MZ7CGinthalf.bdf

OK, but not ideal. Problems with cursor not present when on a blank space… How is cursor chosen?

Anyway, the threequart(er) size one also looks excellent, since 24 and 28 have 4 as a common factor.

The cursor seems to be the empty space drawn in reverse, but it does not work here.

See ~/bin/mzterm … heh heh heh.

 cat  ~/bin/mzterm

rxvt -g 88x50 -cr white -pr white -bd blue -fg white -bg black -fn -unknown-mz7int1-medium-r-normal--16-160-72-72-c-240-fontspecific-0
#rxvt -g 88x50 -cr white -pr white -bd blue -fg white -bg black -fn -unknown-mz7cgintt-medium-r-normal--18-63-200-200-p-107-fontspecific-0 -e clearsh
#rxvt -cr white -pr white -bd blue -fg white -bg black -fn -unknown-mz7cgint-medium-r-normal--21-75-200-200-p-128-fontspecific-0 -e clearsh
#rxvt -cr white -pr white -bd blue -fg white -bg blue -fn -unknown-mz7cgint-medium-r-normal--21-75-200-200-p-128-fontspecific-0 -e clearsh
#xterm  -sb -leftbar -cr white -bd blue -fg white -bg blue -g 88x50 -fn -unknown-mz7int1-medium-r-normal--16-160-72-72-c-240-fontspecific-0

Still no cursor, though… don’t know why.

gdbfed can open the MZ-700 ROM directly as a console font…doofus.

Just need to put in an average width… BUT, the encoding is of course all over the shop.

Step 1 is to put out first half of the ROM to MZ7int1.ROM
Step 2 is to open this in gbdfed (console font)
Step 3 is to re-encode correctly:

$ mv MZ7int1.bdf MZ7int1_recode.bdf

Then change the encoding number in the file. I can’t be bothered right now. Easiest would be to use the re-encoding table I put into the C file for mz2mf to make the tex font… Done.

OK, play with scale of it using bdfresize — just 2 3 4x for now Done.

OK, these are the better fonts. No need to go via LaTeX. Just note it as possible and move on! Descenders are getting chopped off by the next line, but I don’t really care.

mzterm launches a terminal widow using the font. It is cute to do the white on blue look like the old machine, but directory names don’t look too good…

Translated all glyphs by 2 in Y to try to increase leading.

Copy to ~/.fonts/mz then cd there and mkfontdir etc

And here’s a picture….


Ugly or what? The old Sharp defaulted to white on blue, so how about this:

$ xterm -sb -leftbar -cr white -bd blue -fg white -bg blue -g 88x50 -fn -unknown-mz7int1-medium-r-normal--16-160-72-72-c-240-fontspecific-0 &


Oh, enough wastage.


nu and vee, I and l — design of physics books and modern fads for fonts


As someone working in a technical field, I often feel like designers do not really appreciate the subtleties of notation and how to make it clear. In the title of this post, ‘I and l’ is upper case ‘eye’ and lower case ‘el’. Not that you can tell.

For example, because so many symbols are used, formulas can often contain symbols which might be mistaken for each other. The classic example is…ilb1

and here is the same formula using some sans serif fonts, using Microsoft Word…


Now, this is not to criticise these fonts. They are just not designed for this job. It is the chooser of the font who is being a wee bit silly if these fonts are used in a mathematical document. An even trickier example is…


which I have produced in LaTeX, and the nu and vee are well-differentiated, but that is because the font was designed by someone (Knuth) with the express purpose of laying out mathematics.

If I was able to give advice to anyone out there designing a text with mathematics in it, it would be to look at the two letter/symbol pairs I have shown here, and make sure they can be told apart. If not, the font choice is a poor one and needs to be changed. And what is fashionable at the moment is irrelevant beside the need for clarity and the fight against ambiguity and lack of precision.


Rant over.

A further little trick with tlmgr: Trouble downloading and unzipping

Went to install some LaTeX packages I needed and typed this at the command line:

$ tlmgr install comment

which gave

[1/1, ??:??/??:??] install: comment [248k]
Useless content call in void context at /usr/share/perl5/LWP/Protocol/ line 379.
TLDownload::get_file: response error: 400 FTP return code 000 (for
TLUtils::download_file: persistent connection ok, but download failed:
TLUtils::download_file: retrying with wget.

TLUtils::download_file: retry with wget failed:
did not succeed, please retry.
TLPDB::_install_package: couldn't unpack to /home/username/installs/texlive/2015/texmf-dist
tlmgr: package log updated: /home/username/installs/texlive/2015/texmf-var/web2c/tlmgr.log


This is ungood. I had already made sure I was using the correct repository, so I knew it was not that. But tlmgr has a switch to force it to use a new connection to the server, rather than trying to reuse a ‘persistent’ one. If the persistent one fails it falls back on wget, which is what the error message above sort of says; what it does not make clear is that the download still failed for some reason.

It is possible to force tlmgr to make a fresh connection each time, and this will work on a wider variety of routers, wifi networks and the like:

$ tlmgr --no-persistent-downloads install chemfig

And this worked a treat. The option can be set in the config file.

$ tlmgr conf tlmgr

shows which configuration file tlmgr is using. It may not exist yet.


$ tlmgr conf tlmgr persistent-downloads 0

has the result of setting non-persistent as the default behaviour, but the documentation is flaky (it says you need an equals sign in there, but that seems to mess it up).

If you then rerun

$ tlmgr conf tlmgr

you’ll see that the configuration value indeed seems to have been inserted into some configuration path somewhere. When I installed a package it worked without the command line flag.


Nothing else.

A little trick with tlmgr: Unknown directive …containerchecksum error

Went to install some LaTeX packages I needed and typed this at the command line:

$ tlmgr install etoolbox

which gave

Unknown directive ...containerchecksum c59200574a316416a23695c258edf3a32531fbda43ccdc09360ee105c3f07f9fb77df17c4ba4c2ea4f3a5ea6667e064b51e3d8c2fe6c984ba3e71b4e32716955... , please fix it! at /home/username/installs/texlive/2015/tlpkg/TeXLive/ line 210,  line 5579.


Turns out the problem was that tlmgr was accessing the 2016 repository when I have the 2015 installation. So I could either update to 2016 or tell tlmgr to use an archived repository.

Since LaTeX evolves fairly slowly, I went with the latter. I didn’t feel like using up my bandwidth. So on the command line I ran:

$ tlmgr option repository

which gave

tlmgr: setting default package repository to

and then all was well.

This was all prompted by using moderncv LaTeX package, and I have noticed that when moving from an older to a newer version of it, I had to move the \begin{document} command a little higher in the .tex file, for some reason.

Nothing else.

Step-by-Step Install of Debian 8.4 on my old NetBook: A successful but too-long Odyssey

My NetBook is a Acer Aspire D255E with an Atom N550 and 1GB RAM and 260GB HD. It is about 5 years old now, with a BIOS date in late 2010.

I put Win 10 on it and stripped away some cruft and its runs pretty well, similar to Win 7, but I don’t like the extra rubbish MS have packed into Win 10, especially the way it handles updates. Since I use Debian at home and RHEL at work, and most of what I do on the NetBook uses programs like LibreOffice and LaTeX, which are open source, and cygwin, which imitates Unix/Linux, I thought the time had come to toast the HD and put Debian on. Having said that, this is Debian using systemd, which is new to me and has been controversial. I shall be interested to see what changes, if any, are apparent. If Slackware 14.2 was out I would seriously consider that.

Issues: Where I am, I cannot access the network without logging in through a pop-up-enabled browser.  Thus I cannot do a network-based install until I have a working browser.  As a result, I first downloaded and burned the eight (8!) CDs in the Debian disk set (here, at UNSW in my case) — I am using an external USB CD drive for the install media, an ASUS SDRW-08D2S-U

Step by step.

  1. I downloaded the disk images and burned them to CDs using a desktop (Windows) machine. Windows 7 and up comes with an iso burning tool, easily accessed through right-clicking on an iso file in the file manager. A distinct improvement.

  2. I put disk 1 in the USB CD drive and rebooted the NetBook, hitting F2 to bring up the BIOS menu. Went to ‘BOOT’ options and moved the USB CDROM option to the top. (BIOS recognised the CD drive — very helpful.)

  3. Saved and exited and let it boot.

  4. Selected ‘install’ from the boot menu.

  5. Selected language, time zone, key map.

  6. Waited for a bit, then chose the wireless network interface.

  7. Problem — I normally have to log into the network through a browser. So…

  8. Oh well, chose Do Not Configure at This Time and went on.

  9. Created root password and a user.

  10. Set time zone in detail.

  11. Manual partition. The partitioner was pretty easy. Selected things by hitting enter, chose options by arrowing up and down the menus. I have 250GB to play with, so I decided to be generous (that is quite a lot relative to what I intend to use the old machine for — it is not like I am going to be editing videos).  So I wanted 40GB root, 5GB swap, rest as /home. I won’t come close to using up these amounts of space.

    1. Deleted existing partition structure (nothing is done till I choose to write anyway).

    2. Created 40GB ‘/’ (root) partition. Set as ext4 file system and bootable. Selected ‘Finished setting up partition’.

    3. Created new partition in remaining space — 5GB — ‘use as’ select swap. Done.

    4. Set up the ‘/home’ partition by selecting defaults, then said, yes, write it to disk! This removes all data from the hard drive, so I made sure I backed up anything I wanted beforehand.

  12. It then installed the base system from the CD.

  13. Said Yes, I want to select a mirror.

  14. No internet, so chose to install ‘standard system utilities.’

  15. Installed GRUB to the HD.

  16. Removed CD and rebooted. Did not get a GUI. Logged in at text console and tried…

  17. Xorg -configure


  18. Used apt-cdrom add to add the CDs in the disk set to /etc/apt/sources.list.
  1. Thought maybe installing more bits of X would automagically cause the dependency-fixing tools in Debian to sort things out. Tried reinstalling xinit but not good, so, what if I try installing a big X-based package and see if it drags in all the dependencies for me (I am no expert; seemed worth a try)…

    apt-get install mate
  2. No good — ‘Dependency problems’ … how can that be when I have not installed anything but from the install media using the approved tools? I have never had issues like this with Debian before…

  3. Tried

    apt-get -f install
  4. It seemed there was no display manager installed…? Huh?

  5. Well, tried typing


    got a very bare X terminal. But it was X. That meant I might be able to run a browser and therefore log into the WiFi (no text browsers that I know of can log in to the network available).

  6. apt-get install iceweasel
  7. Errors – why? Dunno.

  8. Tried

    apt-get -f install


  9. Now seemed ok. Iceweasel ran. Tried to set up mirrors and log in to network. But there was apparently no network. Well, in fact there should have been wired and wireless.

  10. Installed synaptic to help search for available programs to help me out! Thought maybe if I could get onto a current mirror I ccould get it to sort itself out. I wish Slackware 14.2 was released.

  11. But for the moment I was restricted to using the disk set… tried installing MATE through synaptic… Nope, problems. ‘Dependency problems’. Are there more disks?

  12.  apt-get -f install

    again, then MATE again – seemed to be working, as if through repeated applications of ‘-f’ I was cycling back and forth towards a working system.

  13. Tried a reboot.
  14. Logged in (text console) then ran


    then in the resulting terminal window typed

  15. Seemed to run. Used synaptic to install network-manager (still restricted to using the disk set). Seemed to work.

  16. Rebooted.

  17. Installed wdm to given some kind of display manager —  for some reason the MATE install did not depend on that! wdm is a good one as it has very few dependencies compared to kdm or gdm.

  18. Reinstalled xinit, xorg (just because I could). Rebooted.

  19. Now had a graphical login prompt (wdm) and logged into MATE and… I was on the (wired) network!

  20. But… ifconfig did not show a wireless adapter. Should it? I am no guru.  Oh, whatever. I have other things to do.

  21. But first, reinstalled mate-applets, since I could not find the network manager applet.  Still could not find it. Turned out…

  22. …There were dependency problems: installer could not find python-gtk2 and python-glade2. That figures, it would be Python. How I hate it. But since I now had wired network, I should have been able to ensure the installer can find whatever it needed by setting up a mirror, so added a mirror to /etc/apt/sources.list — I used the UNSW mirror.

  23. Reinstalled wireless-tools, since I am now in the habit of reinstalling things. Ran apt-get -f install again out of habit.

  24. Then

    apt-get update

  25. Then

    apt-get if install

  26. Then

    apt-get autoremove

  27. Then

    apt-get upgrade

  28. Then

    apt-get install network-manager-gnome

  29. Then rebooted, and it found the wireless networks ok. So looked promising.

  30. Now, smaller issues: The card reader did not work, and sound did not seem to be working either. Found this very helpful page on the web: and then installed the (non-free) firmware. Turned out that the driver had been added to firmware-linux-nonfree in ‘Jessie’, the current Debian (‘8.4’, I prefer to call it), so:

     apt-get install firmware-linux-nonfree

    which worked without any issues.

  31. Rebooted, and the card reader worked. At some point sound also started working. Webcam works too… guvcview, fswebcam take care of that.

  32. Installed LaTeX according to my own instructions, using tlmgr rather than Debian packages. That needed installation of Tk, which was fine.

Conclusions: Now that it is done, I am glad. For two reasons. One, it is over and it was much more trouble than I expected. Two, the machine is faster and more responsive than when it ran Windows, whether Win7 or Win10. Linux does a better job of managing the battery (it could tell that my old battery only works at about 40% of original capacity, and warned me as such) and seems to drain it more slowly. Boot time is about halved and I can interact meaningfully with the desktop almost immediately. The install seemed to need a lot of going back and forth between installing stuff and ‘apt-get -f install’ to fix it and then back again, and using disk sets was a pain; swapping the disks in and out of the external optical drive repeatedly was tedious, and something about the disk sets seemed to be incomplete and I could only finally get things working by gaining access to a network mirror, suggesting that the best way to install would have been to use the ‘netinstall’ media and find a network elsewhere that the install program could access directly without my having to log in through a working browser (I have used network install in the past, where you boot from a smaller CD image that then downloads everything from a mirror, and never had so much trouble). Installing the non-free firmware seemed to be the only ‘tweak’ required, though.

So very good but does not dovetail well with WiFi networks that need you to log in through a browser session. Perhaps an install from a live disc would have worked better, since they give you a working browser…

I am very happy with the combination of MATE and Debian. Took a bit longer to get there than I had hoped, is all.

And it’s done.

Problems with epstopdf: Image sizes in pdflatex wrong compared to LaTeX

Okay, this is a note to myself.

I made an EPS (encapsulated PostScript) using gsview (see this post).  Then when I run LaTeX everything looks nice.  I handed the files off to the collaborator who wanted them (I was just handling the Word to LaTeX process) and they compiled them and got a tiny graphic in a big white space.

Left: The document <tt>latex</tt>ed. Right: Same document, <tt>pdflatex</tt>ed.

Left: The document latexed. Right: Same document, pdflatexed.

What was going on?  Well, my colleague’s TeX GUI program (I don’t use one, and I don’t know what they use.  Some Windows GUI I think) automagically converted the EPS to PDF — which it did because its default setting (I am guessing) was to use pdflatex — but the conversion was dodgy and it did not keep the EPS bounding box, but put the graphic on an A4 (or letter paper perhaps) page.  Now why would it do that?

I took a look at the first few lines of the EPS file.  They look like this:

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 88 536 446 715
%%HiResBoundingBox: 0 0 595.00 842.00

A-ha (I thought at the time)! The ‘HiResBoundingBox’ is clearly not being set by gsview, and presumably this is the bounding box being used by epstopdf, the command line tool used to convert (I had tried running epstopdf directly on the EPS file but the resulting PDF had the same problem as when the PDF was produced automatically by the GUI). So I copied the ‘BoundingBox’ numbers into the HiRes field and changed them to be reals by putting ‘.0’ on the end (that’s a nought, not the letter ‘o’).

And it did not work.  This leads me to suggest that epstopdf has its problems.  But, anyway, the solution is… pdfcrop by Heiko Oberdiek. As simple as:

pdfcrop fig1.pdf fig1_crop.pdf

and then use the cropped PDF in the document and all is well!