Archive | LaTeX

# $$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

\documentclass[fleqn]{article}
\begin{document}
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}.$
\end{document}


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:

\setlength{\mathindent}{0pt}


and this gives

Anyway.

# 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%.
• 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}.

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-breaking en rule in Word; results of stretching a hyphen.

My Word.

# My new work profile.

I am now officially an editor… http://www.biotext.com.au/staff/darren-goossens/. From the company website:

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…

_________________________________________________________________

Package: gbdfed (1.5-1.1)

https://packages.debian.org/squeeze/gbdfed

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

then

$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 ~/.fonts/mz/MZ7CGint.bdf $ 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 Then: $ 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 ftp://ftp.tex.ac.uk/tex-archive/fonts/modes/modes.mf 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

Rant.

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…

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.

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/ftp.pm line 379. TLDownload::get_file: response error: 400 FTP return code 000 (for ftp://tug.org/historic/systems/texlive/2015/tlnet-final/archive/comment.tar.xz) TLUtils::download_file: persistent connection ok, but download failed: ftp://tug.org/historic/systems/texlive/2015/tlnet-final/archive/comment.tar.xz TLUtils::download_file: retrying with wget. TLUtils::download_file: retry with wget failed: ftp://tug.org/historic/systems/texlive/2015/tlnet-final/archive/comment.tar.xz Downloading ftp://tug.org/historic/systems/texlive/2015/tlnet-final/archive/comment.tar.xz did not succeed, please retry. TLPDB::_install_package: couldn't unpack ftp://tug.org/historic/systems/texlive/2015/tlnet-final/archive/comment.tar.xz 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. Typing $ 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. Good. 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/TLPOBJ.pm line 210,  line 5579.


Whoa!

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 ftp://tug.org/historic/systems/texlive/2015/tlnet-final


which gave

tlmgr: setting default package repository to ftp://tug.org/historic/systems/texlive/2015/tlnet-final


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

…failed.

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

xinit

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

(again)

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

xinit

then in the resulting terminal window typed

mate-session
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

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: http://blog.dale.id.au/ene-technology-inc-sd-card-reader-ub6250/ 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.

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 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!

Minorness.