This question of how to include text that will appear in html but not pdf has been answered twice (LaTeX multicolumn block in Pandoc markdown and Pandoc markdown: Omit text in PDF version but include in HTML version) and I applied the solution recommended:
Here is the source:
My text.
<div>
This will be ignored in non-HTML output
</div>
Other text
The command I used was:
pandoc essai.md --from=markdown-markdown_in_html_blocks -o essai.pdf
Yet the text between the <div>tags is still displayed in the pdf file.
Am I missing something obvious? Or has the behaviour of pandoc changed since 2013/2014 (my version is 1.19 of 2016)? If yes, what would the solution be?
I know you asked for a solution that works with pandoc 1.19, but for completeness, here is one which is a bit cleaner but only works with pandoc 2.0 and later:
There is a new raw_attribute extension, which allows to do the following:
`text in html`{=html}
`text in pdf`{=latex}
It is enabled in pandoc markdown per default.
I found an answer: add the -native_divs extension.
This way:
$ pandoc essai.md --from=markdown-markdown_in_html_blocks-native_divs -t latex
My text.
other text
My understanding is that pandoc has started interpreting <div> items as "native" elements, i.e. represented in the AST, which causes the interesting side effect that a <p> is added in html. This behaviour needs to be deactivated in order to obtain the desired effect.
If someone has a better solution or a better explanation, please let me know.
Related
I'm trying to generate a PDF from a basic HTML page using pandoc, but it seems like a table (or a few) are preventing the PDF from being generated.
This is the page I'm trying to convert to a PDF document. Here is the command that I'm running:
$ pandoc --verbose --from=html --to=pdf --output=ch3.pdf --pdf-engine=xelatex -V geometry:margin=1.5in https://bob.cs.sonoma.edu/IntroCompOrg-x64/bookch3.html
And here is the end of the output generated:
Error producing PDF.
! Argument of \LT#nofcols has an extra }.
<inserted text>
\par
l.2588 \begin{longtable}[]{#{}r#{}}
I was able to save it as a markdown document, and then convert that markdown document to PDF, but the tables become a block of incomprehensible markdown text. I suspect that something is going wrong in the translation of the table elements, but I don't know anything about latex so I can't say for sure, and have no idea where to start debugging. Any help is appreciated, thank you!
I am trying to convert a markdown document to HTML, using pandoc. I cannot get the HTML output to create the table of contents correctly.
Issue:
I have added a table of contents to the markdown doc, where clicking on each header takes the reader to the relevant section. I am using the format below, where clicking on 'Header Title' will send the reader to the section 'header' in the document:
[Header Title](#header)
I tried to convert this to HTML using the pandoc command
pandoc -i input.md -f markdown -t html -o input.html
This creates a valid HTML file I can open in Firefox, and the items in the table of contents show up as links - but when I click them, nothing happens (I am expecting it to jump to the relevant section)
This happens when I use either markdown or markdown_github as the input format (-i in pandoc)
Question:
How can I get the table of contents to show the expected behavior in HTML?
Or is the concept of 'table of contents' a wrong approach to HTML, and I should change my markdown code?
Apologies if I am going about this the wrong way, I have no experience with HTML / web documents.
I found a couple of similar questions but they seemed to be specific to other programming languages / tools, so any help how I can achieve this with markdown / pandoc is much appreciated.
I am using pandoc 1.19.2.4 on Ubuntu.
Example markdown:
- [Chapter 1](#chapter-1)
- [1. Reading a text file](#1-reading-a-text-file)
## Chapter 1
This post focuses on standard text processing tasks such as reading files and processing text.
### 1. Reading a text file
Reading a file.
Looking at your markdown file, you have used #1-reading-a-text-file as the id for the 1st subheading.
While converting it to HTML, the following line is generated for the subheading:
<h3 id="reading-a-text-file">1. Reading a text file</h3>
The problem is the mismatch of "#1" which is present in the table of contents, but not in the heading.
My guess is that pandoc does not allow HTML id to start with a number.
Changing the table of contents to the following should work:
- [Chapter 1](#chapter-1)
- [1. Reading a text file](#reading-a-text-file)
I'm looking to create a mostly markdown document, but would like to take advantage of inserting HTML when I might need a bit more control over formatting on a case-by-case basis. I have iaWriter on macOS and am able to do so, and from my understanding of markdown this is an included behaviour.
When using pandoc on my linux machine, however, some tags (most notably <i> tags at the moment) are not interpreted.
My markdown file is:
This _does_ work.
This does <i>not</i> work.
However, inserting a <p>tag</p> will create a line-break and new paragraph.
When I execute pandoc -o test.pdf test.md I get the result: test.pdf
I've tried a few extensions in the output (+raw_html, +inline_code_attributes) thinking maybe I was missing something but have so far not found an explanation.
Apologies if this is a duplicate, but I was unable to find it, and have so far been unable to source an answer.
Thank you.
See the pandoc MANUAL: Creating a PDF.
By default, pandoc will use LaTeX to create the PDF Therefore, raw HTML will be ignored and would only have an effect if your output format is HTML as well. However, you can use wkhtmltopdf instead of pdflatex to go from markdown to PDF via HTML, instead of via LaTeX.
From the raw HTML extension docs:
The raw HTML is passed through unchanged in HTML, S5, Slidy, Slideous, DZSlides, EPUB, Markdown, Emacs Org mode, and Textile output, and suppressed in other formats.
Introduction
I'd like to create source code in latex in order to produce pdf via pdflatex and html page(s) via pandoc. I use the following source
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[magyar]{babel}
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
\item \label{itm:thefirst}
First example point
\end{enumerate}
This is an example to demonstrate how \textbackslash label\{\} and \textbackslash ref\{\} are not working with pandoc. Here should be a reference to the first example: \ref{itm:thefirst}
\end{document}
This can be compiled with pdflatex without any error or warning.
Problem
I create the html page via pandoc using the following code:
pandoc -f latex sample.tex -t html5 -o sample.html -S --toc -s
but it creates unsatisfactory results around the label and the reference:
<body>
<ol>
<li><p>[itm:thefirst] First example point</p></li>
</ol>
<p>This is an example to demonstrate how \label{} and \ref{} are not working with pandoc. Here should be a reference to the first example: [itm:thefirst]</p>
</body>
Question
What shall I modify in the latex source code in order to get something like this:
<body>
<ol>
<li><p id="itm:thefirst">First example point</p></li>
</ol>
<p>This is an example to demonstrate how \label{} and \ref{} are not working with pandoc. Here should be a reference to the first example: (1)</p>
</body>
What shall I modify in the latex source code [...]
Pandoc does currently not support parsing and processing of \label{...} or \ref{...} from LaTeX files, so there is no easy solution to your problem.
Why not go an alternative way?
Instead of writing your sources in LaTeX, write them in Markdown.
That way it will me much easier to convert the sources to HTML as well as to LaTeX and PDF.
As a bonus, you also get top-notch support to convert the sources to EPUB, DOCX, ODT and much more....
I am editing a lot of documents in latex that consist of code listings and are currently output to pdf.
Since I am working in teams on those documents, I often need to manually integrate changes done by group members to the latex source.
Most of the group members do not know latex, so I would like to have a means to enable them to do the document formatting in a style maybe similar to markdown.
Since the latex documents consist of figures, have references and use the lslisting package, I am wondering if it would be possible to map these specific areas to a simple markdown style syntax.
Workflow Example:
Edit file in Markdown (or similar)
tag sections
tag code areas
tag figures
tag references
convert to latex
automatically convert tags
output
pdf
html
Would it somehow be possible to achieve such a workflow? Maybe there are already solutions to my specific workflow?
Here is an example for Docutils.
Title
=====
Section
-------
.. _code:
Code area::
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
}
.. figure:: image.png
Caption for figure
A reference to the code_
Another section
---------------
- Itemize
- lists
#. Enumerated
#. lists
+-----+-----+
|Table|Table|
+-----+-----+
|Table|Table|
+-----+-----+
Save that as example.rst. Then you can compile to HTML:
rst2html example.rst example.html
or to LaTeX:
rst2latex example.rst example.tex
then compile the resulting LaTeX document:
pdflatex example.tex
pdflatex example.tex # twice to get the reference right
A more comprehensive framework for generating documents from multiple sources is Sphinx, which is based on Docutils and focuses on technical documentation.
You should look at pandoc (at least if I understand your question correctly). It can convert between multiple formats (tex, pdf, word, reStructuredText) and also supports extended versions of markdown syntax to handle more complex issues (e.g. inserting header information in html).
With it you can mix markdown and LaTeX, and then compile to html, tex and pdf. You can also include bibtex references from an external file.
Some examples (from markdown to latex and html):
pandoc -f markdown -t latex infile.txt -o outfile.tex
pandoc -f markdown -t html infile.txt -o outfile.html
To add your own LaTex template going from markdown to pdf, and a bibliography:
pandoc input.text --template=FILE --bibliography refs.bib -o outfile.pdf
It is really a flexible and awesome program, and I'm using it much myself.
Have you looked at Docutils?
If you are an Emacs user, you may find org-mode's markup to your liking. It has very nice support for tables, coordinates well with other Emacs modes like the spreadsheet, and has good export of images to HTML. Cf. the fine manual's HTML-export section.
org-mode files are editable outside Emacs, for team members who do not use it, although the previewing and embedding of other Emacs modes can, naturally, only be done with Emacs.