Hacker News new | ask | show | jobs
by wodenokoto 878 days ago
I write a fair amount of reports professionally and I use word.

Getting data from my Python analysis into the reports are tedious at best and updating numbers last minute is hair pulling frustrating.

But because of the good wysiwyg I can cheat on my adjustments when I need a graph to go “just there”, I can edit my paragraph wording such that I don’t get a almost completely blank page in between sections, etc, etc which is important to make a good looking report, imho.

How do you go about that with rst? I’d love to write a templates rst file that can be fed from my excel sheets and Python scripts, but how do I go about final layout adjustments?

4 comments

I've gone a few routes. I have used sphinx's singlehtml builder to make a huge HTML file and then used pandoc to convert it into docx for final adjustments. This worked surprisingly well on a 2000-page document. But it's a bit cludgy.

Another (non-Sphinx) thing you can do is just write (portions of) your docx reports directly from Python using python-docx [1]. I use this approach when people give me strict docx templates that need to be filled in from Python in a very specific way. It can drop data-generated tables in at special placeholder sections and everything.

[1] https://python-docx.readthedocs.io/en/latest/

I will say that I've been more and more happy with just using sphinx straight to pdf for very professional looking reports. Given some latex preamble work in the config you can get it looking quite nice. I haven't personally struggled recently with too many egregious formatting issues on the sphinx-built latex stuff. You do have to swap over to landscape mode for large tables, etc. so it takes some work. But you're right that in many cases, formatting issues do still happen, so YMMV.

Another neat trick in sphinx is the csv-table directive [2], which loads table data directly from a csv file you have around, which you can obviously get from your xlsx.

[2] https://docutils.sourceforge.io/docs/ref/rst/directives.html...

I do something similar for my reports. I write most of it in markdown using Typora and then I export the last draft to docx for fine tuning and distribution (the agencies I work with want docx submissions, not pdf, which always bothers me).

Typora uses pandoc to do the conversion. My reports are mainly text, charts, and lots of math formulae and it works great. You don't get fine adjustment of layout, but I find that a feature not a bug. I see so many people waste time to put a figure in just the right place. It doesn't matter. The goal is clear information transfer so just get the figure in the doc where it makes sense and go on.

There's a lot you can do with latex to automatically import data and update automatically from external sources, and while it might seem counter-intuitive it is much easier and less effort than Word's wysiwyg interface.
I'm jealous of how easy it is to import data when using a structured source code like format such as rst, markdown or latex. I'm sticking with word because I can easily do small layout adjustments like decreasing the margins of a table to make it fit on a page, or easily see when a paragraph is 1 or 2 words too long, causing it to shift all sorts of elements across pages.
You can do that with Latex as well? I use TexStudio which has a preview pane. Any time I make changes I hit f5 and it updates pretty quickly. It's not instantly but pretty close to it, and there are already less problems with things shifting around because it manages that better than Word does, by design.
I've recently switched to Quarto[0] with RStudio desktop[1] as the editor. It's my preferred approach for all writing now:

1. Great markdown editor with both source and WYSIWYG views

2. Render to a wide range of formats including html, pdf, epub, docx

3. Generate books, web sites, single page docs, presentations

4. Incorporate code (like jupyter) except the source is plain text with fenced blocks

5. Supports code in a number of languages including Python and R.

6. Can use other editors too (iirc there's a plugin for VS Code though never tried it).

7. Built in support for MathJax for mathematical formulae and Mermaid for text-based diagramming with auto inline preview

I prefer it to Word for writing and jupyter for notebooks. No affiliation to Posit, the company that develops both Quarto & RStudio. Just a fan of the products.

--

[0]: https://quarto.org/ [1]: https://posit.co/download/rstudio-desktop/

Try out Typst.

It senses changes to any file and auto-updates the doc lightning fast - it's far better than LaTeX IMO

No HTML export yet. Which this post is about.

Though I too like typst and am subscribed to their Github issue for HTML export, that maybe some day will be available.