Thursday, September 10, 2015

LaTeX: Putting answers to selected exercises in an appendix to a book

The LaTeX package answers is designed to deal with this.  Most of the online help relates to using it with an article documentclass.    I used it like this, in a book using the memoir documentclass (which allows both A5 (option a5paper) and US Trade (option ebook) paper sizes.  The bit that caused trouble, and which is handled here, is to make sure that the solution is fully and correctly labelled with the coordinates of the exercise, including the subsection number and the sequence number in the subsection, taking account of the fact that only certain numbers in the sequence have solutions.

In preamble:

\usepackage{answers}
%Exercise:
\newtheorem{Exc}{Exercise}[subsection]
%exercise without answer:
\newenvironment{ex}{\begin{Exc}\normalfont}{\end{Exc}}
%exercise with answer in appendix:
\newenvironment{exw}{\begin{Exc}%
\Writetofile{answers}{\textbf{\thesubsection.\arabic{Exc}}}%
$\dagger$\normalfont}{\end{Exc}}
\Newassociation{sol}{Solution}{answers}
\renewcommand{\Solutionlabel}[1]{\null}% suppresses the label

At the start of the document:

\begin{document}
\Opensolutionfile{answers}[exanswers]


In the text:

1. An exercise without a solution:

\begin{ex} Show that
$f(A_1\cup A_2)= f(A_1)\cup f(A_2)$.
\end{ex}

  -- This will set the exercise with a label like

1.2.3.1 Exercise Show that ...

where 1.2.3 is the subsection number, and this is the first exercise in that subsection. The "1.2.3.1 Exercise" will be in bold, and the rest in the ambient normalfont of the document.

2. An exercise with a solution:

\begin{exw} Write out the proofs of all the
remaining identities in the Proposition.
\end{exw}
\begin{sol}
Hint: Imitate the proof given for the first one.
\end{sol}

 -- This will set the exercise with a label like

1.2.3.2 Exercise $dagger$ Write out ...

where 1.2.3 is the subsection number and this is the second exercise in it.  $dagger$ will print as a dagger, flagging the fact that there is a solution given later.  The 1.2.3.2 and the material in the sol environment will be enclosed in a Solution environment and written out to the file exanswers.tex.

Finally, at the point where answers are to appear in the appendix:

\Closesolutionfile{answers}
\input{exanswers.tex}


Tuesday, December 16, 2014

Multicolumn document in LaTeX

I wanted to make a flier for a book I'd published, and found a quick solution here:

http://timmurphy.org/

This great site has tons of technical solutions.

Thursday, October 9, 2014

Converting M/S Word to LaTeX source. Hex codes

I know there is some tool out there that does this, but if  it's just a matter of fixing a few
characters that seem to vanish when you export the word doc to plain text,
then it's useful to know that the unicode hex for

... (ellipsis) is 2026
long dash is 2013
hyphen is 2d
left double quote is 201C
right double quote is 201D
left single quote is 2018
right single quote is 2019

To find the code for a character (visible or not) in a file
open with vi, move the curso to it and type ga

Examples:

To convert all double left quotes to the LaTeX equivalent in vi:
:1,$s/\%u201C/\\lq\\lq/g


e with an acute accent is unicode hex 00e9, so to convert them all to LaTeX:
:1,$s/\%u00e9/\\'e/

Mixing greek and latin text in LaTeX Ubuntu

Don't use the math mode $\alpha$, etc for ordinary greek words.

$ sudo apt-get install texlive-lang-greek

Add to preamble:
/usepackage[greek, english]{babel}
% makes latin/english the default

In the document, switch in and out of greek with
\greektext .... \latintext ...

This allows you to type greek on your keyboard.

An alternative is the switch with
\begin{greek} .... \end{greek}
I haven't used this. It's possibly better for extended greek text.
I've just been interested in putting in occasional words and
short phrases.

Example:

These grounds are quite sufficient for deeming
mathematical training an indispensible basis of real
scientific education, and regarding, with Plato,
one who is \greektext `agewm'etrhtoc%
\footnote{\latintext -- {\it ageometretos }, i.e. ignorant of geometry
(or, perhaps, unskilled in geometry, or indifferent to geometry).
The motto said to have been
carved above the entrance to Plato's
Academy was: \greektext O`udeic `agewm'etrhtoc e`is'itw --
\latintext {\it Let no-one
ignorant of geometry enter.}}
\latintext as wanting in one of the
most essential qualifications for the successful cultivation
of the highest branches of philosophy.
}


How to use Sumatra pdf reader on Ubuntu

Download the windows executable SumatraPDF.exe
and (install and) use wine.

To use it by default, make a script, say sumatra, that does
wine SumatraPDF.exe $1
and make it the default by picking any pdf, right-click -> properties -> open with
and selecting sumatra.

(I found Adobe heavy with Ubuntu Linux 14.04 on an old computer, and inclined
to freeze or crash. Sumatra is much leaner and faster, and works fine.)

Embedding fonts in a pdf made with pdflatex, linux

$ pdf2ps file.pdf
$ ps2pdf -dPDFSETTINGS=/prepress file.ps file-w-embedded-fonts.pdf

(If you don't do this, then the software reading the pdf may make
font substitutions.  This matters if it is proprietary software used by
some printer, for instance.)

Canon MF3010 scanner on Linux Ubuntu 14.04

The MF3010 printer/scanner would print but not scan on Ubuntu, when I first got it. This has now been sorted out, at least to the extent that I can scan.  I'd like to acknowledge the help of the Ubuntu Forum. It has this nice feature that you can sign up to receive an email whenever there is a new post on a specific topic.

Step 1: I first followed these instructions to
download and build sane-backend from source:

In a new subdirectory $HOME/MF3010/sane-backends:

$ sudo apt-get install libusb-dev
$ git clone git://git.debian.org/sane/sane-backends.git
$ cd sane-backends/
$ ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
$ make

(For more detail see:

 http://jonathan.bergknoff.com/journal/scanning-ubuntu-canon-mf3010

The instructions at the end of that piece,
involving moving stuff in the system, are deprecated in the
forum, and anyway can't be used as they stand with Ubuntu 14.04.

Note that libusb is an absolute prerequisite for
any kind of sane functionality.

The make step takes a long time, with many warnings, but
works, as far as I can see.)

Step 2: Second, I uninstalled the version of libsane that came
with Ubuntu14.04.  This automatically removed xsane and
simple-scan as well.  I used the package manager with the GUI,
Ubuntu Software Center.

Third, in directory $HOME/MF3010.sane-backends:

Step 3:
$ sudo make install

With that done,
$ scanimage -V
gives:
scanimage (sane-backends) 1.0.25git; backend version 1.0.25

(Note: you have to have a match of versions here. If you get

scanimage (sane-backends) 1.0.25git; backend version 1.0.23

it means that the old libsane was not removed, or has crept back in.
It will creep back in if you try to reinstall simple-scan
with the package manager, and you'll have to go back to step 2.
)

$ scanimage -L
gives
device `pixma:04A92759' is a CANON Canon i-SENSYS MF3010 multi-function peripheral

You are now good to go.
$ scanimage -h
gives help.

$ sudo scanimage >filename.pnm
gives scary warnings, and I hope I haven't just installed
a trojan, but it
scans whatever is on the scanner plate and saves it as a pnm,
which you can manipulate using gimp (for instance)
into any format you like.