Need newbie-help with markdown in pandoc

Hi,

1st: Sorry for the text being a “little” longer ;-)… but I really need help with this…:

I begun to read about the markdown language and the converter pandoc. I find this is a super cool way for producing multiple outputs, like docx, pdf, html.

I am not a programmer, I only known bash-scripting and html/css for doing my websites.

My goal is: I am writing a personal “wiki”… a kind of knowledge database. In the past I did it in LibreOffice, but I find the idea of writing in plaintext way more easy and better to handle.

I found that software “remarkable”, which can produce such pdf or html files:

And, with a single click, I can for example choose the theme “solarized dark”:

Thats cool so far. The drawbacks: Remarkable does not work anymore under 20.04 (neither deb, nor snap, etc…)… and it cannot export to docx for example.

So my decision was to learn markdown and pandoc, also to not be dependent on a software that is perhaps no longer maintained.

I have now read about 2 weeks about pandoc and markdown. I sure can convert a markdown file like

pandoc file.md -o file.docx

This is the markdown-text:

And this is for example what outputs to docx:

But: I am totally NOT able to change any of the styling of the docx file. I also tried it via latex into a pdf. It always gets a “default” look.

But I have no clue how to “style” my output files.

Question: is is correct that I would have to define all “stylings” for multiple output formats like docx, html, pdf separatly?
I tried a lot with template-files under
/usr/share/pandoc/data/templates

But I am not able to change a single thing of the look of my output. Also the pandoc manual is very huge.

My 1st goal would be, to get a pdf out of my markdown file that is styled like the “solarized dark themed” by remarkable, but via cli and pandoc.
My 2nd goal is to learn how to define the look of my outputs…

Perhaps pandoc and markdown is way more complicated… but I am thinking of something like css: defining a css style called “h1”, and then tell in a file that “h1” is fontsize blabla, font, color, padding, etc… or isnt it such simple?

Perhaps some of you is familiar with markdown / pandoc… and could just help me with the start… I am sure I can get there once I got help with the starting…

I would be super happy about every answer, personal messsage, also via telegram @pragomer or here in the forum.

Kind regards

Pragomer

I would recommend TiddlyWiki. It’s a personal wiki program that allows you to write in markdown and use whatever theme you want! https://tiddlywiki.com/. I would be happy to set it up with you, and tell you anything you need to know! It’s also FOSS!

I myself created a simple webpage and as I used Drupal before, the hassle of updating all the time was way overkill for my few pages. So, I also only use html with css nowadays and quit using a cms.

I would suggest to output as an .odt rather than a .docx, as I see you use LibreOffice.
That way you can use a template, according to the Pandoc documentation. I must admit, I haven’t used it myself.
You can find the documentation here: Pandoc - Pandoc User’s Guide.
Hope you succeed in what you’re trying to accomplish!

*** Edit ***
After reading some more, I found out that nowadays it should be possible to create a .docx by using a reference.
I found the following, which is in German, but that is no problem to you. :wink:

Lade das Vorlagen-Muster in Word (.dot / .docx – egal), mache evtl. gewünschte Anpassungen an’n Stilen + speicher’s als DOCX (nicht DOT) unter “my-reference.docx”.
Dann: pandoc input --reference-docx=my-reference.docx -o out.docx

Wirklich erstaunlich, wie viel da geht!

1 Like

I just tested it. I saved a template.docx with Header1 in blue and Header2 in red. I saved it for simplicity reasons in the same folder as the file.md.
It appears that --reference-docx has been removed and that you should use --reference-doc instead.

In the terminal I then typed: pandoc file.md --reference-doc=template.docx -o file.docx

That’s it! Works like a charm!

1 Like

Thank you @GeBo for the hard work, it made this extension post possible.

According to @GeBo’s manual link, you don’t have to create every template but docx and pptx don’t have a template so you have to create your own.

Reference:
Pandoc - Pandoc User’s Guide
“docx and pptx have no template (however, you can use --reference-doc to customize the output).”

For best results you want to follow this guide to get Pandoc to generate a docx template to work with:

Reference:
Pandoc - Pandoc User’s Guide
“To produce a custom reference.docx, first get a copy of the default reference.docx: Pandoc -o custom-reference.docx --print-default-data-file reference.docx. Then open custom-reference.docx in Word, modify the styles as you wish, and save the file. For best results, do not make changes to this file other than modifying the styles used by Pandoc:”

When it’s created and you’ve customized it, you can either specify the file explicitly whenever you generate a docx by using --reference-doc=FILE or you can name it reference.docx and place it in your user data directory so Pandoc uses it automatically. You can find what Pandoc considers your user data directory here:

Reference:
Pandoc - Pandoc User’s Guide

Hope this helps,

1 Like

Hi GeBo,

Ulfnic and I are actually testing this… and it seems not to work… we are using debian and Kubuntu 20.04.
The reference-file that is generated, looks like this:

But no matter how I change and save it (for exmaple all colors to red or so…), using this reference.docx has absolutly no impact on my output file, which I create like so:

pandoc test.md --reference-doc=reference.docx -o test.docx

(all files including the reference.docx are stored in the same folder).

I am wondering what works different for you, GeBo, so that it worked…

I had to grind on this for a bit but I got it to work, the key was this part in the manual:

Pandoc - Pandoc User’s Guide
“The contents of the reference docx are ignored, but its stylesheets and document properties (including margins, page size, header, and footer) are used in the new docx.”

Meaning you’re not supposed to edit the text in the document, it’s only there as a reference while you edit the embedded style sheet and document properties.

Top to bottom instructions:

How to create and use a custom docx template with Pandoc using LibreOffice:

  1. Open a Terminal.
  2. Generate a Pandoc reference.docx which’ll contain the relevant styles:
    pandoc -o custom-reference.docx --print-default-data-file reference.docx > reference.docx
  3. Open reference.docx in LibreOffice.
    ! Do not modify the document text directly !

Change Styling:

  1. On the top menu, click Styles, then Manage Styles (or press F11).
  2. A right menu will appear showing you a selection of style names which correspond to the styled text in the document. Right-click on each style you wish to change and click “Modify…”.
  3. Click “Ok” after modifying each style and the document text corresponding to that style will change.

Change Document Properties:

  1. On the top menu, click Format, then Page…
  2. Pandoc recognizes changes to “margins, page size, header, and footer”, edit accordingly and click “Ok”.

Save:

  1. On the top menu, click File, then Save (Ctrl + S).

  1. Tell Pandoc to use the custom template:
    pandoc mydoc.md --reference-doc=reference.docx -o mydoc.docx
1 Like

Ok. Problem totally solved. Thank you, both, so much for your help, effort and time !

The issue was this: I only edited the existing text, but not the Style Template itself (I thought this would change the default of LibreOffice Writer but it did only for this document).

Special Thanks to Ulfnic who invested such time in my issue and wrote this step-by-step tutorial and explanation.
I am sure this will help many people in the future.

I am always flashed again by how great our community is.

Long live linux

Joe

2 Likes

Sorry I couldn’t be of help, today. Here in Europe it was working hours. :wink:
Yes, indeed, you have to edit the styles, that’s what I did (and always do).

Glad you got it working!

BTW: I didn’t create a reference docx through pandoc. I just opened a new document in LibreOffce, edited the styes and saved that. :face_with_hand_over_mouth:

1 Like