Atom and Pandoc - pandoc

Using Atom, I'm trying to generate a PDF file from markdown.
I installed markdown-preview-plus plugin, which supports pandoc, and then installed pandoc and configured the plugin to use it.
Now, markdown-preview-plus does recognize pandoc, but I cannot see any command to generate a PDF. Plugin's web page seems to say nothing about that.. Can you help me?

markdown-preview-plus
Atom's markdown-preview-plus package generates an HTML preview, as #mb21 alluded to. This is clear by the fact that you can right click on the preview and select Copy as HTML. With the Enable Pandoc Parser option enabled, MPP is indeed using pandoc to generate this HTML preview.
In light of your question, I tried adding the following to the Pandoc Options: Commandline Arguments setting in MPP:
--to=latex, --output=temp.pdf
Note 1: you can't specify --to=pdf because pandoc can only generate PDF by first generating a LaTeX file.
Note 2: the above doesn't work because MPP essentially passes the contents of the editor window through pandoc 'on-the-fly', so you can't really hijack the --output setting.
Workarounds
AFAIK, there is no way to get a "live" PDF preview (the way you can get a "live" HTML preview using MPP). This means you will have to build the document whenever you'd like to view what's changed.
Assuming you want to view the PDF in the Atom window, you can install pdf-view and open the PDF in a pane, side-by-side with your source. Otherwise, you could simply open the PDF in your favorite PDF reader.
Build from the command line
As #mb21 suggested, you can build from the command line. I sometimes use BAT/CMD files to store lengthy, or complicated build commands (since I'm on Windows). For example, in my document source directory, I might have make.cmd, which contains:
pandoc --filter=pandoc-crossref --filter=pandoc-citeproc --smart --listings --number-sections --standalone file.md -o file.pdf
Then I run make.cmd from the command prompt using `./make.cmd'.
Alternatively, you could use Makefile.
Build from Atom
Install atom-script. Then, configure your run options (Ctrl-Alt-Shift-O, on Windows) with something along the lines of the following:
Command: pandoc
Command Arguments: --filter=pandoc-crossref --filter=pandoc-citeproc --standalone file.md -o file.pdf
As you edit your source and would like to update the PDF, you can execute the command via Ctrl-Shift-B
Build from Atom using panzer
You'll still need Atom's script package, but you'll also need to get panzer which is a utility that helps manage build configurations for pandoc.
Edit:
Automatically Build-on-Save via Grunt
Rather than having to press a key combination (e.g. building from command line or using atom-script), I thought of automatically building the output PDF upon saving using Grunt. I've captured the basic idea in this gist

I'm working on the same thing right now, only I am using embedded latex mathematical formulae etc.
The markdown-preview-plus gives a fair representation of what I'm likely to see, but I've been running the following command from the command line in order to compile my pdf
pandoc -f markdown myfile.md -o pdffile.pdf
This works in most simple cases, for trickier ones, or where I want to stitch a few things together, I'm taking my markdown files first to their latex equivalents using a command like
pandoc -f markdown+tex_math_dollars+pipe_tables myfile.md -o myfile.tex
Which creates a latex version of my original file that I can compile/combine with other latex files, or convert to pdf using
pandoc myfile.tex -o myfile.pdf
It's supposed to be possible to embed these various scripts into Atom, using the 'scripts' package, but I'm yet to try that - would be great if someone were to post up their methods too in this direction.

I got pandoc-pdf toolbar working on Atom after installing Perl on Windows, though PDF compilation is much slower with "Latexmk".
I recommend using markdown-preview enhanced and then use several other options available including pandoc, ebook etc.

markdown-preview-enhanced in Atom has support for PDF-on-save, similar to the Grunt workflow suggested above. The output command has several options in addition to PDF, such as MS Word.
Example:
---
layout: post
title: tentative tentacles
date: 2020-09-15 15:01
bibliography: bibliography.bib
output: pdf_document
export_on_save:
pandoc: true
---

Related

how to generate html output in sphinx-needs instead of needs.json

i am trying to use/understand sphinx-needs.
As soon as i run the following command it is generating needs.json
sphinx-build -b needs source build
But how to generate the html output from needs.json?
i don't want to have any custom layouts a default or predefined layouts (such as'complete') will do
Thanks for your answers
I have generated my sphinx folders using the quickstart command
$ sphinx-quickstart
you will have something that looks like this
After writing your needs in .rst format
the following command will generate the html files.
$ make html
PS: You should not have any dependency problems.
Sphinx-needs need to be installed separately.

How to compile a lex file on windows?

I have correctly downloaded and installed flex, bison and Dev C++ in C:\ . Then I tried to compile myfile.l in command prompt, but it gives the error:
flex: can't open myfile.l.
What is the problem?
I can see from your question that you are a beginner in need of some instruction, so what follows is in tutorial style. I hope you don't mind the tone. Many of my students encounter the same problem as you did when first starting.
The files containing the code for flex, bison or the compiler gcc (or g++) are just text files, and not some specially encoded form of file. They are only named something.l, something.y and something.c (or something.cpp) by convention. We could just call them something.txt or even something.l.txt if we wanted to. The reason they are named the way they are is to enable all the different components of one program to be distinguished without cluttering up the name space. So, if we have a project, such as some homework done in flex and bison, we can use the word homework as the base name and have the following file set:
homework.l <-- The lexer source file for flex created for the homework
homework.y <-- The parser source file for bison created for the homework
homework.cpp <-- The C++ source file for g++ created for the homework
homework.obj <-- The object file created by g++
homework.exe <-- The final windows executable created by g++
(There will be many other files as well, but I'll skip over that for now).
As the source files are just forms of a text file they can be created by a text editor. You indicated you are using Dev C++ which is an IDE (Integrated Development Environment) which combines a text editor, a compiler and a debugger into one package. The text editor part works just like any other text editor, such as Notepad, NotePad++, vim, emacs or one of the myriad of other editor tools.
Commonly, by default, a text editor tool on Windows will save a text file with the postfix language code of .txt. Here is an example dialogue of saving such a file:
You can see that if I saved my file, which I called SOlexer.l by pressing the Save button, I would get a file called SOlexer.l.txt because the default is to always make a file withe the suffix of .txt.
Now this does not need to be a problem. If I tried to invoke flex, as you did:
$ flex SOlexer.l
flex: can't open SOlexer.l
I would get the same error message. However I can just call flex with the actual file name used and it would work:
$ flex SOlexer.l.txt
$
Alternatively, I could rename the file, and then use it:
$ rename SOlexer.l.txt SOlexer.l
$ flex SOlexer.l
$
Problem solved!
However, as you have discovered, it is best to just create the file with the desired (and more convenient) name in the first place. To do this one has to just make a different selection from the menu when saving the file, like this:
If we click on All types (*.*) we can create the file without the .txt suffix. This should work for most similar tools also.
To help my students who had difficulty using flex and bison on Windows I made a series of video tutorials. You are welcome to use them also.
In conclusion, although you had trouble getting your flex file to build, your problem is nothing to do with flex or bison, but a simple beginners problem with learning how to create and edit files on a Windows system.

Use feh to open graphviz (dot) files

in past, I used feh to open directly the *.dot files (from Graphviz), which was great, as I didn't have to convert each *.dot file to jpg/pdf individually in order to display them (although, I imagine that it must have done it automatically there). I often get generated a lot of DOT files in different folder. However, after reinstalling my OS (Mageia), it stop working. I guess, normally feh is not supposed to open dot files, however, I got used to it. I know I could have written a script which would convert DOT to PNG in a tmp directory and open it with feh. However, does anybody know how to do it directly with feh (as I did in past)?
Now, if I type:
>feh graph.dot
feh WARNING: graph.dot - No Imlib2 loader for that file format
feh: No loadable images specified.
See 'man feh' for detailed usage information
So my question is rather how to include support for dot files into the Imlib2 loader?
Thanks a lot.

where file is saved in wkhtmltopdf

I want to use wkhtmltopdf for html to pdf conversion. The program seems to work but I dont know where the target file is saved. Ideally it should be saved in programfiles-->wkhtmltopdf folder.
Does anyone experience this problem before?
When you generate the document, you choose where to save the file. Refer to their usage wiki page for simple examples on how to use it. There is also a manual for the various options and detailed information on it. You can find different versions of the manual here.
Usage:
wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file>
Examples:
wkhtmltopdf http://google.com example.pdf
wkhtmltopdf http://google.com f:\example.pdf
If you choose the first example, the file will be saved in which ever directory you are currently located in.

How can I convert Markdown documents to HTML en masse?

I'm writing some documentation in Markdown, and creating a separate file for each section of the doc. I would like to be able to convert all the files to HTML in one go, but I can't find anyone else who has tried the same thing. I'm on a Mac, so I would think a simple bash script should be able to handle it, but I've never done anything in bash and haven't had any luck. It seems like it should be simple to write something so I could just run:
markdown-batch ./*.markdown
Any ideas?
Use pandoc — it's a commandline tool that lets you convert from one format to another. This tool supports Markdown to HTML and back.
E.g. to generate HTML from Markdown, run:
pandoc -f markdown index.md > index.html
This is how you would do it in Bash.
for i in ./*.markdown; do perl markdown.pl --html4tags $i > $i.html; done;
Of course, you need the Markdown script.
If you have Node.js installed, then you can use the [MdPugToHtml] converter (https://www.npmjs.com/package/md-pug-to-html). It massively converts Markdown to Html. Moreover, it is possible to use Pug templates, but you can use them without templates.
The conversion is performed in the terminal with just one command:
npx md-pug-to-html /home/content
where:
npx is an npm command that installs md-pug-to-html at the first launch, and then launches the md-pug-to-html converter.
/home/content is a directory with your Markdown files. You may have another one.
The converter has various settings and can be used both in the CLI command line and has an API for use in applications.
There is detailed documentation on the MdPugToHtml converter in English and Russian.
You can do this really easily with VS Code. (Well, this is not a command line tool, but proved itself to be super helpful.)
Install the Markdown All In One extension by Yu Zhang
Open the VS Code Command Palette (Ctrl-Shift-P), and select Markdown All In One: Print documents to HTML (select a source folder)
Tip: If you want to make your export portable, you want to change absolute image paths to relative paths by using the following setting in your settings.json (Ctrl-Shift-P -> Preferences: Open Settings (JSON))
"markdown.extension.print.absoluteImgPath": false
In this way, after conversion, just copy all non-markdown files (images) to the destination folder and the HTML pages are portable.
I use this in a .bat file:
#echo off
for %i in (*.txt) python markdown.py "%i"
// using Bash in mac
for i in *.md; do asciidoc $i; done;

Resources