Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

Sunday, October 22, 2017

ghostscript crashes when embedding fonts in a pdf: caused by png file

I'm using Ubuntu 14.04. I had this problem with a book. I prepared LaTeX source, say book.tex, use pdflatex book to make a book.pdf, and then needed to embed the fonts to send the file to the printer. To do this I usually use the sequence of terminal commands:
pdf2ps book.pdf
(which outputs book.ps) and
ps2pdf -dPDFSETTINGS=/prepress book.ps book-w-embedded-fonts.pdf

But having used this many times without problems, and through several revisions of the text, it crashed one day while executing the last command. The command ps2pdf invokes ghostscript, or gs, with suitable arguments, so this appears as a crash of gs, and the crash dump is placed in /var/crash with a name that tells you it was gs that crashed.

The problem remained after I installed all software upgrades.

To isolate the problem, I used a bisection search on the source, and it turned out that the crash was caused by the inclusion of a png-format graphic file, using \includegraphics from the LaTeX package graphicx. (This was tedious to locate, because there was no problem with pdflatex, I had no idea of the nature of the problem, and for each step of the binary search I had to re-run the font-embedding commands, which take minutes.)

I'm not sure what the problem was with the png file, but I just used gimp to make an equivalent jpg file, and used that instead, and that got me past the problem. The crazy thing about this is that there are other png files included in the source, and they were similarly generated (using Sage) and, even stranger, the same file worked in an earlier draft. It seems unlikely that it was corrupted, since I was able to load it into gimp and make the jpg from it.

The main reason for this post is to flag that it might be useful to check any png-format files, if you ever encounter the same problem.

It would be more satisfactory if I could understand the problem, rather than just walking around and past it. It appears that ps2pdf with this flag is not just adding font data to the pdf file, but is also doing something with the embedded graphics. Can anyone answer these questions:
1. Does pdflatex put a full native pdf description of the included graphics into the output book.pdf, or does it rely on an external graphics engine to render graphics?
2. Same question for pdflatex followed by pdf2ps: what is in the postscript file, in relation to the included graphics? I notice that book.ps is about 5 times larger than book.pdf.

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}


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.
}


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.)