01-25-2010, 05:04 AM | #1 |
Grand Sorcerer
Posts: 9,707
Karma: 32763414
Join Date: Dec 2008
Location: Krewerd
Device: Pocketbook Inkpad 4 Color; Samsung Galaxy Tab S6
|
LaTeX, a way to PDF
I'm always looking for new (for me) formats to create my books in. I have two readers that I use regularly. One is the JE-100, an LCD, WinCE based reader, on which I use Mobipocket (for various reasons) and on which I'll probably keep on using this format. But my other reader is a BeBook Mini (Hanlin v5) on which I now also read Mobipocket format. I don't like the Epub implementation (lack of top/bottom margin, weird page number in the right margin, no progress bar visible and other irriations...). And while the Mobipocket format has less irritations, it still isn't exactly what I want (the main irritation with that format is the fact that it doesn't remember what font you've used last, I always have to select the font I want to use, every time I open the book again).
So, I was thinking about transforming my HTML sources (which I use to generate both Mobipocket and Epub books) into PDF. I first used a HTML2PDF converter, but found the lack of hyphenation in HTML (which doesn't bother me with the Mobipocket implementation) generated some highly irritating sentences in PDF (in Mobipocket, I might get a few words on a sentence with large spacings between the words, in the PDF document, I got large spacings between the letters of the words...). I finally decided to give up on the HTML2PDF directly and started looking into LaTeX. The learning curve of LaTeX is rather steep. At least, if you have to figure out everything from scratch (with a little help from knowledgeable people). But, I won't be stopped by a few setbacks, so, I got to work. I first installed MikTex 2.8 and then TexNicCenter (1.0 Stable RC1). And then it was time for my first LaTeX PDF document. Code:
\documentclass[12pt,openany,oneside]{book} \begin{document} Hello World! \end{document} Code:
\documentclass[12pt,openany,oneside]{memoir} \usepackage[papersize={4in,5in},margin=3mm]{geometry} \begin{document} Hello World! \end{document} Code:
\documentclass[12pt,openany,oneside]{memoir} \usepackage[papersize={4in,5in},margin=3mm]{geometry} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} Lorem ipsum dolor ... <snip> ...velit tellus vitae velit. \end{document} Code:
\documentclass[12pt,openany,oneside]{memoir} \usepackage[papersize={4in,5in},margin=3mm]{geometry} \makechapterstyle{normal}{% \setlength{\beforechapskip}{0pt} \setlength{\midchapskip}{0pt} \setlength{\afterchapskip}{20pt} \renewcommand{\printchaptername}{} \renewcommand{\printchapternum}{} \renewcommand{\chaptitlefont}{\centering\LARGE\clfamily} \setsecnumdepth{chapter} } \makechapterstyle{simple}{% \setlength{\beforechapskip}{50pt} \setlength{\midchapskip}{10pt} \setlength{\afterchapskip}{20pt} \renewcommand{\chapnamefont}{\normalfont\Large\bfseries} \renewcommand{\chapnumfont}{} \renewcommand{\chaptitlefont}{\chapnamefont} \setsecnumdepth{part} } \chapterstyle{simple} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} Lorem ipsum dolor ... <snip> ...velit tellus vitae velit. \end{document} So, now I have a nice document, with a chapter and text. But I still don't have a page number (so I can see my progress in the book, it's something I really want). Back to the drawing board! Code:
\documentclass[12pt,openany,oneside]{memoir} \usepackage[papersize={4in,5in},margin=3mm]{geometry} \makechapterstyle{normal}{% \setlength{\beforechapskip}{0pt} \setlength{\midchapskip}{0pt} \setlength{\afterchapskip}{20pt} \renewcommand{\printchaptername}{} \renewcommand{\printchapternum}{} \renewcommand{\chaptitlefont}{\centering\LARGE\clfamily} \setsecnumdepth{chapter} } \makechapterstyle{simple}{% \setlength{\beforechapskip}{50pt} \setlength{\midchapskip}{10pt} \setlength{\afterchapskip}{20pt} \renewcommand{\chapnamefont}{\normalfont\Large\bfseries} \renewcommand{\chapnumfont}{} \renewcommand{\chaptitlefont}{\chapnamefont} \setsecnumdepth{part} } \chapterstyle{simple} \makeoddfoot {plain}{}{}{\footnotesize page \thepage\ of \thelastpage} \makefootrule {plain}{\textwidth}{\normalrulethickness}{\footruleskip} \makeoddhead {plain} {}{}{\footnotesize\thetitle} \makeheadrule {plain}{\textwidth}{\normalrulethickness} \pagestyle{plain} \title{Book Title} \author{A. Uthor} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} Lorem ipsum dolor ... <snip> ...velit tellus vitae velit. \end{document} After some more digging (and especially some errors! as at one point I did see my header and footer, but simply lost part of my text, which were, I presume, "written" behind them...", I found my answer" "includeheadfoot". Almost done, but there's a lot of wasted space between the header and the body and the footer and the body. Code:
\documentclass[12pt,openany,oneside]{memoir} \usepackage[papersize={4in,5in},margin=3mm]{geometry} \makechapterstyle{normal}{% \setlength{\beforechapskip}{0pt} \setlength{\midchapskip}{0pt} \setlength{\afterchapskip}{20pt} \renewcommand{\printchaptername}{} \renewcommand{\printchapternum}{} \renewcommand{\chaptitlefont}{\centering\LARGE\clfamily} \setsecnumdepth{chapter} } \makechapterstyle{simple}{% \setlength{\beforechapskip}{50pt} \setlength{\midchapskip}{10pt} \setlength{\afterchapskip}{20pt} \renewcommand{\chapnamefont}{\normalfont\Large\bfseries} \renewcommand{\chapnumfont}{} \renewcommand{\chaptitlefont}{\chapnamefont} \setsecnumdepth{part} } \chapterstyle{simple} \setlength{\headsep}{1mm} \setlength{\footskip}{7mm} \makeoddfoot {plain}{}{}{\footnotesize page \thepage\ of \thelastpage} \makefootrule {plain}{\textwidth}{\normalrulethickness}{\footruleskip} \makeoddhead {plain} {}{}{\footnotesize\thetitle} \makeheadrule {plain}{\textwidth}{\normalrulethickness} \pagestyle{plain} \title{Book Title} \author{A. Uthor} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} Lorem ipsum dolor ... <snip> ...velit tellus vitae velit. \end{document} But another problem has arisen. Now, my bottom margin is rather big. That is, the space between my page number and the bottom of the page. I couldn't figure out that one, until I put the /setlength commands above the "geometry" line. I also changed my margins a bit, so I only had a tiny margin on the top and bottom and a somewhat bigger on the side. Code:
\documentclass[12pt,openany,oneside]{memoir} \setlength{\headsep}{1mm} \setlength{\footskip}{7mm} \usepackage[papersize={4in,5in},hmargin=3mm,vmargin=1mm]{geometry} \makechapterstyle{normal}{% \setlength{\beforechapskip}{0pt} \setlength{\midchapskip}{0pt} \setlength{\afterchapskip}{20pt} \renewcommand{\printchaptername}{} \renewcommand{\printchapternum}{} \renewcommand{\chaptitlefont}{\centering\LARGE\clfamily} \setsecnumdepth{chapter} } \makechapterstyle{simple}{% \setlength{\beforechapskip}{50pt} \setlength{\midchapskip}{10pt} \setlength{\afterchapskip}{20pt} \renewcommand{\chapnamefont}{\normalfont\Large\bfseries} \renewcommand{\chapnumfont}{} \renewcommand{\chaptitlefont}{\chapnamefont} \setsecnumdepth{part} } \chapterstyle{simple} \makeoddfoot {plain}{}{}{\footnotesize page \thepage\ of \thelastpage} \makefootrule {plain}{\textwidth}{\normalrulethickness}{\footruleskip} \makeoddhead {plain} {}{}{\footnotesize\thetitle} \makeheadrule {plain}{\textwidth}{\normalrulethickness} \pagestyle{plain} \title{Book Title} \author{A. Uthor} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} Lorem ipsum dolor ... <snip> ...velit tellus vitae velit. \end{document} I now have a nice basic template for my books. I've tried to change the default font, and managed doing that, but the font I really like doesn't seem to work (http://www.tug.dk/FontCatalogue/venturis2/). I did install it, but I get an error when I try to create the PDF. I finally did manage to install the TTF I'm using on my Mini with mobipocket books so, at least that's working (only took me the entire weekend to get it working ) Now, this works on my computer screen, but how does it look on my BeBook Mini? Well, apparently, a 5" screen doesn't mean my screen is 4" by 3". When I put the ruler beside the screen, it measures 10cm by 7.5cm (more or less). Which is less than 4x5". But when I put those numbers in, it looks horrible. So, after a lot of tweaks, I settled on 4x5.3". That way the page is large enough, the top and bottom margins aren't huge and the font size is comfortable to read (for me). Now I can write an application which can transform my HTML files into TeX files (not only replacing HTML tags, but also the HTML characters, such as — and all those accented letters...) But I think that part will be easier than figuring out the LaTeX commands, as my HTML is all custom made and very simple in syntax. After that, I'll need to really figure out how to make new chapter templates, as not all chapters are created equal... Also, how to make links (if that actually works in PDF) for my TOC's... ------------------------ If anybody has some comments, improvements, hints, tips, extras, anything, I'm here, listening! (or rather, watching...) |
01-25-2010, 09:10 AM | #2 |
Member
Posts: 13
Karma: 2136218
Join Date: Jan 2010
Device: BEBOOK
|
a bebook (e-reader) latex class
I created a bebook class, to make pdf's that are perfect to read on my bebook.
And it really reads incredibly well, pleasant and smooth. I even forget about the rather small paper/screen size. Maybe you can use this as a start to implement your template as a class file. This will make your tex file(s) cleaner. Like this: Code:
\documentclass{bebook} \begin{document} \chapter{Your chapter title} some text ... \end{document} Code:
% TODO: del. pagenumbers, pass options, set position of title % PART I: Identification %************************************** \NeedsTeXFormat{LaTeX2e} \ProvidesClass{bebook}[2010/01/19 Jans Bebook Class] % PART II: Preliminary declarations %************************************** \LoadClass{book} % Specify which packages to use: % fancyhdr - used for the header and footer %\usepackage{fancyhdr} % lastpage - used to get the number of pages for making a page 1 of 3 footer %\usepackage{lastpage} % graphicx - used to include graphics \usepackage{graphicx} % geometry - used to set up the layout \usepackage[lmargin=2mm, rmargin=2mm,tmargin=2mm,bmargin=2mm]{geometry} % xcolor - used to enable colors! %\usepackage{xcolor} % colortbl - used to enable tablecolors! %\usepackage{colortbl} % multirow - for tables with rowspan cells %\usepackage{multirow} % ifthen - used for declaring some commands with variables %\usepackage{ifthen} % sectsty - used to change the section headers a bit (sectionstyle package) %\usepackage{sectsty} % hyperref - used to include a clickable email address with mailto. \usepackage[pdftex,a4paper]{hyperref} \hypersetup{ bookmarks=true, % show bookmarks bar? unicode=false, % non-Latin characters in Acrobat’s bookmarks pdftoolbar=true, % show Acrobat’s toolbar? pdfmenubar=true, % show Acrobat’s menu? pdffitwindow=false, % window fit to page when opened pdfstartview={Fit}, % fits the width of the page to the window pdftitle={My Book title}, % title pdfauthor={your name}, % author pdfsubject={title}, % subject of the document pdfcreator={your name}, % creator of the document pdfproducer={your name}, % producer of the document pdfkeywords={some keywords, in a list, with commas}, % list of keywords pdfnewwindow=false, % links in new window colorlinks=false, % false: boxed links; true: colored links linkcolor=black, % color of internal links citecolor=black, % color of links to bibliography filecolor=magenta, % color of file links urlcolor=black % color of external links } \setlength\paperheight{120mm}% \setlength\paperwidth{90mm}% \setlength{\textwidth}{86mm} \setlength{\textheight}{116mm} % PART III: Options %************************************** % this passes unkown options to the book class \DeclareOption*{ \PassOptionsToClass{\CurrentOption}{book} } % process all options \ProcessOptions % PART IV: More declarations %************************************** % New and renewed commands % define some stuff to do at the begin of the document \AtBeginDocument{ } A table of contents is done by the command (surprise surprise): \tableofcontents On my bebook the structure is also nicely reflected in the menu (button 7) The only downside is copying all the text in the chapters and putting brackets around it which is a little too timeconsuming. note: fancyhdr is also a great package to get your headers and footers the way you want. Last edited by janneman; 01-25-2010 at 09:18 AM. |
Advert | |
|
01-25-2010, 09:41 AM | #3 |
frumious Bandersnatch
Posts: 7,536
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
That's a long post!
Well... first: have you tried Prince to convert HTML to PDF? It has hyphenation, kerning, proper paragraph justification... You could even use my epub2pdf.sh script (or similar) to directly convert ePUB to PDF. As for the LaTeX template, if you are using the memoir class, you don't have to use the geometry package, but use the class's methods instead. I admit I don't fully grasp how the different paramaters interact with each other, but this seems to work: Code:
\usepackage{calc} %just to be able to use + in the dimensions \setstocksize{5in}{4in} %set the paper size \settrimmedsize{\stockheight}{\stockwidth}{*} %the used space is just the paper size \setheadfoot{10pt}{7mm} %header and footer separations \setheaderspaces{*}{1mm}{1} \setlrmarginsandblock{3mm}{3mm}{*} %horizontal margins \setulmarginsandblock{1mm+\headheight+\headsep}{\footskip+\baselineskip}{*} %vertical margins \checkandfixthelayout %make everything consistent (this is needed) Code:
\documentclass[12pt,oneside]{memoir} %you don't need "openany" with "oneside" \usepackage{calc} \setstocksize{5in}{4in} \settrimmedsize{\stockheight}{\stockwidth}{*} \setheadfoot{10pt}{7mm} \setheaderspaces{*}{1mm}{1} \setlrmarginsandblock{3mm}{3mm}{*} \setulmarginsandblock{1mm+\headheight+\headsep}{\footskip+\baselineskip}{*} \checkandfixthelayout \chapterstyle{simple} \setsecnumdepth{part} \makeoddfoot {plain}{}{}{\footnotesize page \thepage\ of \thelastpage} \makefootrule {plain}{\textwidth}{\normalrulethickness}{\footruleskip} \makeoddhead {plain} {}{}{\footnotesize\thetitle} \makeheadrule {plain}{\textwidth}{\normalrulethickness} \pagestyle{plain} \title{Book Title} \author{A. Uthor} \begin{document} \chapter{1. Lorem} \label{sec:1. Lorem} ... \end{document} |
01-25-2010, 10:04 AM | #4 | |||
Grand Sorcerer
Posts: 9,707
Karma: 32763414
Join Date: Dec 2008
Location: Krewerd
Device: Pocketbook Inkpad 4 Color; Samsung Galaxy Tab S6
|
I actually wrote down the steps I did, and then decided to post them
Quote:
Quote:
Quote:
|
|||
01-25-2010, 10:23 AM | #5 | |
frumious Bandersnatch
Posts: 7,536
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
I prefer ePUB as a source rather than HTML because ePUB is better for distribution (it's already an ebook format). Since ePUB has HTML under the hood, you don't have to lose anything either. |
|
Advert | |
|
01-25-2010, 10:43 AM | #6 | ||
Grand Sorcerer
Posts: 9,707
Karma: 32763414
Join Date: Dec 2008
Location: Krewerd
Device: Pocketbook Inkpad 4 Color; Samsung Galaxy Tab S6
|
Quote:
But I'd love to know how you get the structure in the menu button! Can you point out what part of your class does that? Quote:
|
||
01-25-2010, 01:28 PM | #7 | |
Member
Posts: 13
Karma: 2136218
Join Date: Jan 2010
Device: BEBOOK
|
Quote:
The memoir class doesn't do this?? You can always add additional bookmarks manually (or with your script) using the hyperref package Code:
\pdfbookmark[level]{Name of bookmark}{your_label} Then they show up in the bookmarks menu of your pdf and thus also in the menu of your bebook. This might be of interest to you, describes options when making a pdf from latex: http://www.mpch-mainz.mpg.de/~joeckel/pdflatex/ And this one might be what you are trying to program??: http://html2latex.sourceforge.net/ Last edited by janneman; 01-25-2010 at 01:34 PM. Reason: added a link |
|
01-25-2010, 01:43 PM | #8 | |
Grand Sorcerer
Posts: 9,707
Karma: 32763414
Join Date: Dec 2008
Location: Krewerd
Device: Pocketbook Inkpad 4 Color; Samsung Galaxy Tab S6
|
Quote:
The page on hyperlinks is useful, though. |
|
01-25-2010, 05:56 PM | #9 |
Reader
Posts: 520
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
|
AFAIK the memoir class has similar commands for headers and footers as fancyhdr. On the other hand fancyhdr also works with memoir. (BTW, I am the author of the fancyhdr package.)
|
01-25-2010, 06:22 PM | #10 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
If you'd like to see code for another ebook created in LaTeX, I have the source code for my version of Introduction to Mathematical Philosophy posted here. It's a mess by comparison, however, since I use the same .tex file for 6 different PDF outputs. I used a reader.sty file I found here in MobileRead some time back, though it doesn't do anything you can't do easily with the geometry package. Fancyhdr and titlesec can cover the rest.
Last edited by frabjous; 01-25-2010 at 07:18 PM. |
01-25-2010, 06:55 PM | #11 |
Reader
Posts: 520
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
|
@frabjous:
What did you use to generate the HTML? |
01-25-2010, 06:58 PM | #12 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
I actually made the HTML first, and then converted it (with RegExs) to LaTeX -- took forever. I don't recommend doing it the way I did.
|
01-25-2010, 07:02 PM | #13 |
Reader
Posts: 520
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
|
Doing the math with HTML must be quite a chore.
|
01-25-2010, 07:16 PM | #14 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
It's more philosophy than math -- while there is some, the mathematical notation is fairly light.
Actually, I had a much worse time converting this web page here from LaTeX to HTML, which, even though it's not my area, I took on since I'm the only one on the editorial staff who knows both mark-up languages. Needless to say, this would get much easier once MathML becomes more widely supported, but in the meantime, I had to make do with CSS tricks to try to emulate things LaTeX does effortlessly. |
01-26-2010, 07:10 AM | #15 |
Grand Sorcerer
Posts: 9,707
Karma: 32763414
Join Date: Dec 2008
Location: Krewerd
Device: Pocketbook Inkpad 4 Color; Samsung Galaxy Tab S6
|
I made some minor adjustments to my preamble and document structure and now I have something into which I can put my HTML sources.
I added: \usepackage[bookmarks,bookmarksopen,bookmarksopenlevel=0,color links,linkcolor=black,urlcolor=black,pdfhighlight= {/N},pdfstartview={100},pdfpagelabels=true]{hyperref} And I think this one caused my TOC to show in my reader menu. I removed the makechapterstyle{normal} (still can't figure out why it didn't work earlier...) I added: \begin{center} \thispagestyle{empty} \includegraphics[width=95mm,height=118mm]{images/cover.jpg} \clearpage \end{center} so I now even have a cover page! But, how can I make this cover page ignore the margins, header and footer of my document? The header and footer don't get shown (\thispagestyle{empty}) but the space is still reserved... and I added: \tableofcontents But I don't like the way the chapter names are shown. Also, the header "Content" has the same layout as the other chapters of the book. How can I make it different? (so, no spacing above the Content header, for example, and a smaller font for the chapter names?) and I did look at the fancyhdr package but couldn't make hear nor tails out of it... And what I did also seem to work The conversion from the HTML into LaTeX isn't too hard, in my case, as my HTML setup is very simple, only using <p>, <div> and <h2> mostly. I'll figure out the footnotes (<a>), images (<img>) and subchapters (<h3>) at a later date . Things like <i> and <b> and such are easy to replace. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Latex, PDF and the PRS-600 Dictionary | s3ntient | 4 | 11-06-2009 10:35 AM | |
Chaîne complète d'édition : HTML, LaTeX, PDF, EPUB à venir. | Randy11 | Software | 2 | 04-05-2009 12:42 PM |
PDF Generated with LaTeX for the iLiad | Hadrien | iRex | 17 | 07-25-2008 10:59 AM |
latex template for sony reader pdf | technicolor | Sony Reader | 10 | 07-25-2008 10:51 AM |
PDF creation from Latex using CJK fonts | alanine | iRex | 0 | 10-14-2007 12:45 AM |