Converting code listings from mediawiki to latex using pandoc - latex

Is there an easy way to say pandoc converter I wish to replace all my source codes in mediawiki article convert to an lstlisting environment on its Latex output?
At this moment, all my <source lang="c"> some code... </source> environments are converted into something like this
\begin{Shaded}\begin{Highlighting}[]
\NormalTok{ some code \textless{}\textless{} }\DecValTok{1}\NormalTok{ \CommentTok{// set... \end{Highlighting}
\end{Shaded}
Not only the code is completely unreadable but also my Latex distribution is not able to translate the code and is missing probably some packages.
I wish to have simply \begin{lstlisting} some code \end{lstlisting} at the output with no additional changes to the code itself.
And I don't speak Haskell, believing there should be an easier way...

Solution was very simple. There is a --listings command line option solving this problem as Sam Carter pointed out.

Related

How to use latex standalone package with knitr?

I'm trying to generate png pictures of charts using knitr and latex standalone package. The following minimal code compiles but the output is pdf:
\documentclass[convert=true]{standalone}
\begin{document}
<<test-plot, echo=FALSE>>=
plot(rnorm(10))
#
\end{document}
Now if I want to pass some options to standalone I must use curly brackets after convert=, but simply putting something like convert={true} will produce an error:
! Argument of \#fileswith#pti#ns has an extra }.
...
Something like convert={true, ghostscript, gsexe=gswin64c, density=1200} works fine with tikz charts.
Am I overlooking something or maybe a knitr shortcoming? Any ideas on how to go around?

knitr/rmarkdown/Latex: How to cross-reference figures and tables in 2 different pdf files?

I'm trying to write a scientific article and the associated supplementary materials entirely in RStudio with rmarkdown.
It seems clear that book down is the way to go to cross-reference between files (https://stackoverflow.com/a/38884378/576684), but I also would like to be able to reference figures produced in one pdf in the other pdf.
Although my latex has got quite rusty with time, I imagine it could be achieved as follows:
compile the article tex and SuppMat tex a first time using rmarkdown::render()
compile these tex files from the command line in order to keep the corresponding .aux file with their references (missing references won't be resolved at this time)
recompile the 2 tex files from the command line another time where all references should now be resolved
Is it a reasonable way to do it? am I overlooking something simpler?
In any case, it requires:
a different numbering of figures in each pdf file (covered by https://stackoverflow.com/a/51337664/576684)
to prevent rmarkdown from trashing the .aux files (it seems that pandoc doesn't allow this, hence the need to create the aux file using standalone latex)
to tell latex to use the additional .aux file if it is found (probably using header-includes: in the YAML header). how can I achieve that?
Thank you very much for your help!
It turns out that the xr package is one way to go: https://texblog.org/2016/08/23/adding-references-from-an-external-file/
so this works from R:
rmarkdown::render("myarticle_ms.Rmd",
bookdown::pdf_book(base_format=rticles::plos_article),
clean=FALSE)
rmarkdown::render("myarticle_SM.Rmd",
bookdown::pdf_book(base_format=rticles::plos_article),
clean=FALSE)
tinytex::pdflatex("myarticle_ms.tex", clean=FALSE)
tinytex::pdflatex("myarticle_SM.tex", clean=FALSE)
tinytex::pdflatex("myarticle_ms.tex")
tinytex::pdflatex("myarticle_SM.tex")
with the following in the YAML header of myarticle_ms.Rmd (and the corresponding one the SuppMat file header):
header-includes:
\usepackage{xr} \externaldocument{myarticle_SM}
Hope it makes life easier for a few others :)

usepackage and making macros in ipython notebook

How can user macros and packages be included in the latex rendered in markdown cells in ipython?
e.g.:
\usepackage{amssymb}
\newcommand{kms}{\ensuremath{\mathrm{km~s}^{-1}}
It is possible to define macros in cells with markdown. Just put the \newcommand between $'s:
$\newcommand{kms}{{\mathrm{km~s}^{-1}}}$
(Note that I removed the \ensuremath command, as it is not accessible.)
In any following statement (in the whole notebook) you can call the macro (in a markdown cell only, of course):
$\kms$
I do not know a way to include extra packages :( If you ever learn how, I would also encourage you to use the siuntx package to format units.
The Html notebook use mathjax to render LaTeX, I suggest reading its doc to know wether it is possible and how.

How to prevent LaTeX from hyphenating words containing a dash?

I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.
One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).
Why is defining a new command ugly? It's how \LaTeX\ defines itself.
\def\ObjectiveC{\mbox{Objective-C}}
Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.
As suggested here, you could define a command like this:
\newcommand\dash{\nobreakdash-\hspace{0pt}}
and use it like this
Consider the $n$\dash dimensional manifold ...
Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.

Is there a good and fast way of printing (on paper) code's syntax highlight?

I'm going to a farm. I think there are no computers there, and my laptop is broken. I want to print out the code of some of my projects on A4 paper so I can review it while I'm there. It would be nice if it was printed with syntax highlighting.
Editors: Vim, Notepad++
Code: Html, CSS, Javascript
enscript
pygmentize
In emacs use ps-print-buffer-with-faces. There is also ps-print-region-with-faces for those occasions when you only want part of a file...
Use M-x <command> to invoke commands by name. Use C-h f <command> for help on a command and also to learn what (if any) keybinding it has.
a2ps tool produces nice PostScript files for program listing printing.
Vim has :TOhtml command which produces HTML with current open file highlighted according to Vim syntax coloring. GVim has Syntax -> Convert to HTML menu for this.
If you use LaTeX, look at listings package (pdf documentation at CTAN). It's a very good solution for including your code in documentation/presentation.
All these tools support syntax of many programming (and non-programming) languages.
Editplus prints with syntax highlighting intact

Resources