Sometime you want to use a piece of software or a library, such as Imager Graph are not linked to the fontconfig lib. Because of that, you can't specify fonts by simply using their family name (Like 'FreeSerif' for instance).
So you need a way to resolve a font's family name to the full path of the font files on disk. Here's how to do it for the FreeSerif one:
$ fc-list -f "%{family} %{style[0]} %{file}\n" 'FreeSerif'
FreeSerif Bold /usr/share/fonts/truetype/freefont/FreeSerifBold.ttf
FreeSerif Medium /usr/share/fonts/truetype/freefont/FreeSerif.ttf
FreeSerif Italic /usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf
FreeSerif BoldItalic /usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf
Maybe one day there will be a Perl module bound to the libfontconfig. Until there, a simple system call will probably do for me :)
EDIT 31st Jan 2011:
There's no -f option in older systems, you can also use
$ fc-list 'FreeSerif' file
/usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf:
/usr/share/fonts/truetype/freefont/FreeSerif.ttf:
/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf:
/usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf:
Showing posts with label typography. Show all posts
Showing posts with label typography. Show all posts
Friday, 7 January 2011
Friday, 5 November 2010
XeTeX: Breaking long lines of Japanese (and Chinese) text.
While LaTeX/XeTeX is very good at hyphenating Latin words, I recently came across the problem of overflowing boxes when attempting to typeset a long paragraph consisting exclusively of Japanese characters:
母親が育児を放棄した末、大阪市西区のマンションで幼い姉弟が亡くなった事件。多くの住民が異変に気づきながら、児童相談所(児相)に通報したのは1人だけだった。複数の人が通報していれば、児相の危機感も強まったかもしれない。なぜ通報をためらった
When you render this with XeTeX, you've got a warning that your hbox is overfull, and the rendered result shows an awful truncated Japanese line:
We clearly need to fix this, because most of the time your data will be in the form of a long paragraph without any linebreaks.
In XeTeX-notes.pdf, we learn that we can activate the line-breaking in XeTeX by using:
\XeTeXlinebreaklocale"en"
The locale used doesn't matter much, the important thing is that it activates line breaking for too long lines where the hyphenation mechanism cannot do its job (a long Japanese/Chinese line for instance).
By adding this to your preamble, here's what you get:
Et voilà, lines are broken so all the characters fit in the page width!
Ps: Thanks to Google news Japan for providing example data.
母親が育児を放棄した末、大阪市西区のマンションで幼い姉弟が亡くなった事件。多くの住民が異変に気づきながら、児童相談所(児相)に通報したのは1人だけだった。複数の人が通報していれば、児相の危機感も強まったかもしれない。なぜ通報をためらった
When you render this with XeTeX, you've got a warning that your hbox is overfull, and the rendered result shows an awful truncated Japanese line:
![]() |
| Rendering of an non hyphen-able Japanese line |
In XeTeX-notes.pdf, we learn that we can activate the line-breaking in XeTeX by using:
\XeTeXlinebreaklocale"en"
The locale used doesn't matter much, the important thing is that it activates line breaking for too long lines where the hyphenation mechanism cannot do its job (a long Japanese/Chinese line for instance).
By adding this to your preamble, here's what you get:
![]() |
| A Japanese paragraph with line breaks. |
Ps: Thanks to Google news Japan for providing example data.
Monday, 13 September 2010
LaTeX: Hyphenate single long words in narrow tabular columns
Consider the following LaTeX code:
\documentclass{article}
\usepackage[english]{babel}
\begin{document}
\begin{center}
\begin{tabular}{ | p{2cm} | l | l | p{5cm} |}
\hline
Incredibilidable & foo & bar & baz \\
\hline
\end{tabular}
\end{center}
\end{document}
\documentclass{article}
\usepackage[english]{babel}
\begin{document}
\begin{center}
\begin{tabular}{ | p{2cm} | l | l | p{5cm} |}
\hline
Incredibilidable & foo & bar & baz \\
\hline
\end{tabular}
\end{center}
\end{document}
When you render it, the first column overflows on the second one because 'Incredibilidable' is considered to be the first word of a paragraph, and LaTeX does not hyphenate first words of paragraphs. So here's what you get:
And this doesn't look nice.
To fix this, we're going to tell LaTeX our word is no longer the first of the paragraph. To do that, we insert a zero length horizontal space before it:
\hspace{0pt}Incredibilidable & foo & bar & baz \\
The rendering now turns into:
Et voila!
Subscribe to:
Posts (Atom)



