Lateral Opinion
Available in: Español • English
2008-09-05 18:38:43

rst2pdf 0.7is out, better than ever!

Right on schedule, everything I promised, plus much simpler/smarter font embedding, and maybe a bag of chips. More at http://rst2pdf.googlecode.com.

# •   •  Listen to this post
Topics: programming, python, rst2pdf
2008-09-04 11:08:43

rst2pdf: What will be new tomorrow

Keeping with my new time-based release schedule, tomorrow is again rst2pdf release day! What will be new in 0.7? Several things!

  • Fixed several serious bugs, specially with the handling of literal blocks (preformatteds and code blocks).
  • Implemented a rather neat sidebar/floating block mechanism. It only lets you go float-left or float-right but it looks better than what you get in HTML, at least:
sidebar-beige
sidebar-beige by Roberto Alsina

You can even use it to float almost arbitrary objects, so you can have floating images or floating figures.

  • Fixed the look of hyperlinks. Reportlab had a bug about making some hyperlinks underlined, and those with a black thick underline. Not when you use rst2pdf! Monkey-patched the heck out of that.
  • Table styling. Let me show you:
rst2pdf-tablestyles
rst2pdf-tablestyles by Roberto Alsina

The first row is a header row. It automatically takes the table-heading style.

The following rows are regular, and they take the table style, which has support for zebra tables with alternating colors (white and gray here).

The lone red cell at the right is special. Its content is this:

.. class:: red

red

If you don't know ReST, that means "red" is a paragraph with class red, so it will be styled whatever way that means (here: red background).

Usually that would mean you have a white (or gray) cell with a red paragraph in it. That looks incredibly ugly.

So, rst2pdf tries to be clever: If there is a single element in a cell, it will try to guess the cell background from it.

And as you saw above, it works :-)

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-09-02 23:49:01

rst2pdf: progress in smartframe branch

Yes, it is getting better. Now there are left-floating or right-floating elements, and you can float pretty much anything (except literal blocks, that's a problem) by using the class directive. Here's how it looks:

sidebar-beige
sidebar-beige by Roberto Alsina
# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-31 23:01:50

rst2pdf: smartframes branch

Today I started a branch called SmartFrames. The main goal is to achieve a better text flow in the document (for example, for sidebars), and it is starting to get there, slowly.

Let's consider how ReST sidebars are rendered in the different writers.

We'll work with an ordinary lorem ipsum that has a sidebar declared just before it.

Here's HTML:

sidebar-html
sidebar-html by Roberto Alsina

And here's LaTeX:

sidebar-latex
sidebar-latex by Roberto Alsina

Each one has its good side and its bad side.

The HTML sidebar is a real sidebar, while the LaTex one is some sort of insert.

OTOH, the ragged text against the HTML sidebar is ... horrid.

So, I wanted something at least a bit better than that for rst2pdf. In the best of all possible worlds, it would be the neat text alignment of LaTex with the floating HTML sidebar.

Here's how it looks now:

sidebar-pdf2
sidebar-pdf2 by Roberto Alsina

There are some minor problems with the current implementation, such that the sidebar is always aligned to the top of a paragraph, and some spacing issues.

How is it done? Let me tell you: it was not trivial :-)

In fact it's pretty evil, but here's a quick explanation:

When I get a sidebar flowable, I insert a new frame in the page template where the sidebar should go, then call a framebreak, insert the "real" sidebar, a "framecutter" and another framebreak.

The framecutter is a flowable that does nothing visible, but inserts another two frames, one at the right of the sidebar with the same height, and another below the sidebar, full width.

I need to use the framecutter because I don't know the height of the sidebar until after it's drawn.

So, we now have 4 frames instead of one:

  1. The original frame, covers the whole page, but has a framebreak above the sidebar.
  2. The sidebar frame, which is very tall, but has a framebreak below the sidebar text.
  3. A beside-the-sidebar frame, short and wide, starting at the right of the sidebar.
  4. A below-the-sidebar frame, wide and tall, starting below the sidebar.

The text should flow from 1 to 3 to 4 neatly and the seams shouldn't show.

Here's a picture that MAY make it clear (there are some odd displacements: those were bugs):

sidebar-wires
sidebar-wires by Roberto Alsina

So, I'm not calling it a success yet, but it is looking decent.

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-30 03:00:34

rst2pdf 0.6 is out, get it while it's hot!

Many new features. Custom page layouts! Multiple frames per page! Multiple layouts per document! Cascading stylesheets! Not very buggy! Get it at http://rst2pdf.googlecode.com or via PyPI.

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-30 00:10:33

rst2pdf is going to be one day late. But there's a good reason.

Besides everything I mentioned yesterday, today I implemented two rather important features: cascading stylesheets, and user-defined page layouts. Here is a screenshot:

montecristo-3
montecristo-3 by Roberto Alsina

That neat two-column layout is done by adding this to the stylesheet:

"pageTemplates" : {
  "firstPage": {
      "frames": [
          ["0cm", "0cm", "49%", "100%"],
          ["51%", "0cm", "49%", "100%"]
      ]
  }
},

The name "firstPage" is magical right now, and there's no way to change from one template to another (yet), and until I do that, I won't be releasing.

Here's what cascading stylesheets does. Suppose you want to use A5 paper and size 12 Times New Roman fonts? Here's all the stylesheet you need:

{
  "pageSetup" : {
    "size": "A5",
  },
  "fontsAlias" : {
    "stdFont": "Times-Roman",
  },
  "styles" : [
    ["base" , {
      "fontSize": 14,
      "leading": 16
    }]
  ]
}

Also, you can specify as many stylesheets as you want in the command line. So you can have one that sets the paper size, one for page layout as above, one for font "sets", etc.

Neat, isn't it?

# •   •  Listen to this post

Available in: Español • English
2008-08-28 23:26:36

Rstpdf wil be released again tomorrow. And it's a good release.

How good? Let me tell you...

  • Support for PDF table of contents
  • Section names and numbers in headers/footers
  • Compressed PDFs (or not)
  • Guess image sizes. Specially if you meant to use them in a web page and declared just ":width: 50%"
  • Gutter margin support
  • Raw directive (insert pagebreaks and vertical space manually)
  • Offers a docutils-compliant API (and another API, too)
  • Include full or partial files for code-block. That means you can extract code and show it in your document!
  • Huge code cleanup lead by Nicolas Laurance.
  • Working multilingual hyphenation. You can have a per-paragraph language and hyphenate it correctly.
# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-27 23:46:35

How pretty is rst2pdf's output? Take a look.

I am a big Alexandre Dumas fan. He's the direct ancestor of Neal Stephenson, so many of you should like him too. So I used one of his best books to try some automatic typesetting of project gutenberg texts.

No, the whole book did not convert without errors, and yes, there is some manual work in what you are about to see, but hey, take a look.

Here's a far look of the first two pages:

montecristo-1
montecristo-1 by Roberto Alsina

And here's some detail of the typsetting:

montecristo-2
montecristo-2 by Roberto Alsina

Yes, the typesetting is not really LaTeX quality, but it's not bad, either.

Compare it with the HTML version at project Gutenberg. The typesetting is a thing of beauty compared to that :-(

The image is a picture of Chateau d'If from flickr, released under Creative Commons. The title font is Scriptina, I chose it because it looks 19th century but modern.

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-25 14:42:11

rst2pdf: release fever!

I did a release yesterday, and another today of my rst-to-pdf-without-latex tool. What's new? Here's an incomplete list:

New in 0,4

  • Fixed bullet and item lists indentation/nesting.
  • Implemented citations
  • Working links between footnotes and its references
  • Justification enabled by default
  • Fixed table bug (demo.txt works now)
  • Title and author support in PDF properties
  • Support for document title in header/footer
  • Custom page sizes in stylesheet

New in 0.3

  • Font embedding (use any True Type font in your PDFs)
  • Syntax highlighter using Pygments
  • User's manual
  • External/custom stylesheets
  • Support for page numbers in header/footer

Of course, since I said I would release something every friday, this means I need to find something else to release? ;-)

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English
2008-08-24 13:33:38

rstpdf love: syntax highlighting

This mini-sprint is doing wonders for rst2pdf. Now on SVN: pygments-based syntax highlighting. Example here: rst2pdf's code, in a PDF by rst2pdf.

# •   •  Listen to this post
Topics: programming, python, rst2pdf
Available in: Español • English