I need to convert LaTeX into MediaWiki syntax. The formulas should stay the same, but I need to transform, for example \chapter{something} into = something =.
Although this can be obtained with a bit of sed, things get a little dirty with the itemize environment, so I was wondering if a better solution can be produced.
Anything that can be useful for this task?
Pandoc should be able to do it:
$ pandoc -f latex -t mediawiki << END
> \documentclass{paper}
> \begin{document}
> \section{Heading}
>
> Hello
>
> \subsection{Sub-heading}
>
> \textbf{World}!
> \end{document}
> END
== Heading ==
Hello
=== Sub-heading ===
'''World'''!
pandoc can get your file converted between several different mark-up languages pretty easily, including mediawiki
I found this: plasTeX. With a bit of hacking probably I can produce a renderer for the mediawiki syntax
Yes Pandoc would be the easiest to do that.
pandoc -f latex -t mediawiki --metadata link-citations --bibliography=bibl.bib --csl=cslstyle.csl test.tex -o test.wiki
--metadata link-citations creates hyperlinks with your in-text citations and the bibliography. You can delete this part if not needed.
bibl.bib is the file of the bibliography you used
cslstyle.csl is the style of citation you want. There are lots of choices that can be downloaded from editor.citationstyles.org
test.tex is the file you want to convert from
test.wiki is the output file you want
all the files should be in the same folder otherwise locations should be specified
Related
I am using pandoc and write my text in markdown. To create my own style I use a custom latex template.
I want to style all bold words with a color. So when I type **a word** this word should not only be bold, but also e.g. blue.
Using the following in my latex template file
\newcommand\boldblue[1]{\textcolor{blue}{\textbf{#1}}}
\renewcommand{\textbf}{\boldblue}
gives me an error when converting to pdf using
pandoc myfile -f markdown -t latex --template==mytemplate -o myfile.pdf
which says
TeX capacity exceeded, sorry (grouping levels = 255)
However: when I only set the newcommand
\newcommand\boldblue[1]{\textcolor{blue}{\textbf{#1}}}
I can write $\boldblue{some text}$ within my markdown file and it works.
Question: how do I set a new command for **<word>**?
Thanks!
After some more research I found the following solution using \let which works:
\let\oldtextbf\textbf
\renewcommand\textbf[1]{{\color{blue}\oldtextbf{#1}}}
Using this code in a template file converts markdown's **<some text>** to bold and blue in latex / pdf.
I want to make use of Maxima as the backend to solve some computations used in my LaTeX input file.
I did the following steps.
Step 1
Download and install Maxima.
Step 2
Create a batch file named cas.bat (for example) as follows.
rem cas.bat
echo off
set PATH=%PATH%;"C:\Program Files (x86)\Maxima-5.31.2\bin"
maxima --very-quiet -r %1 > solution.tex
Save the batch in the same directory in which your input file below exists. It is just for the sake of simplicity.
Step 3
Create the input file named main.tex (for example) as follows.
% main.tex
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\def\f(#1){(#1)^2-5*(#1)+6}
\begin{document}
\section{Problem}
Evaluate $\f(x)$ for $x=\frac 1 2$.
\section{Solution}
\immediate\write18{cas "x: 1/2;tex(\f(x));"}
\input{solution}
\end{document}
Step 4
Compile the input file with pdflatex -shell-escape main and you will get a nice output as follows.
!
Step 5
Done.
Questions
Apparently the output of Maxima is as follows. I don't know how to make it cleaner.
solution.tex
1
-
2
$${{15}\over{4}}$$
false
Now, my question are
how to remove such texts?
how to obtain just \frac{15}{4} without $$...$$?
(1) To suppress output, terminate input expressions with dollar sign (i.e. $) instead of semicolon (i.e. ;).
(2) To get just the TeX-ified expression sans the environment delimiters (i.e. $$), call tex1 instead of tex. Note that tex1 returns a string, which you have to print yourself (while tex prints it for you).
Combining these ideas with the stuff you showed, I think your program could look like this:
"x: 1/2$ print(tex1(\f(x)))$"
I think you might find the Maxima mailing list helpful. I'm pretty sure there have been several attempts to create a system such as the one you describe. You can also look at the documentation.
I couldn't find any way to completely clean up Maxima's output within Maxima itself. It always echoes the input line, and always writes some whitespace after the output. The following is an example of a perl script that accomplishes the cleanup.
#!/usr/bin/perl
use strict;
my $var = $ARGV[0];
my $expr = $ARGV[1];
sub do_maxima_to_tex {
my $m = shift;
my $c = "maxima --batch-string='exptdispflag:false; print(tex1($m))\$'";
my $e = `$c`;
my #x = split(/\(%i\d+\)/,$e); # output contains stuff like (%i1)
my $f = pop #x; # remove everything before the echo of the last input
while ($f=~/\A /) {$f=~s/\A .*\n//} # remove echo of input, which may be more than one line
$f =~ s/\\\n//g; # maxima breaks latex tokens in the middle at end of line; fix this
$f =~ s/\n/ /g; # if multiple lines, get it into one line
$f =~ s/\s+\Z//; # get rid of final whitespace
return $f;
}
my $e1 = do_maxima_to_tex("diff($expr,$var,1)");
my $e2 = do_maxima_to_tex("diff($expr,$var,2)");
print <<TEX;
The first derivative is \$$e1\$. Differentiating a second time,
we get \$$e2\$.
TEX
If you name this script a.pl, then doing
a.pl z 3*z^4
outputs this:
The first derivative is $12\,z^3$. Differentiating a second time,
we get $36\,z^2$.
For the OP's application, a script like this one could be what is invoked by the write18 in the latex file.
If you really want to use LaTeX then the maxiplot package is the answer. It provides a maxima environment inside of which you enter Maxima commands. When you process your LaTeX file a Maxima batch file is generated. Process this file with Maxima and process your LaTeX file again to typeset the equations generated by Maxima.
If you would rather have 2D math input with live typesetting then use TeXmacs. It is a cross-platform document authoring environment (a word processor on steroids if you like) that includes plugins for Maxima, Mathematica and many more scientific computing tools. If you need to or are not satisfied with the typesetting, you can export your document to LaTeX.
I know this is a very old post. Excellent answers for the question asked by OP. I was using --very-quiet -r options on the command line for a long time like OP, but in maxima version 5.43.2 they behave differently. See maxima command line v5.43 is behaving differently than v5.41. I am answering this question with a cross reference because when incorporating these answers in your solutions, make sure the changes in behavior of those command line flags are also incorporated.
I would like to have code and an image side-by-side in a Beamer slide.
In LaTeX I would do this with columns. I would like to use markdown within the column structure.
\begin{columns}
\column{.5\textwidth}
~~~~~~~~Python
>>> some python code
~~~~~~~
\column{.5\textwidth}
![](A_generated_image.pdf)
\end{columns}
Unfortunately Pandoc doesn't process the markdown within the \begin{columns} and \end{columns} statements. Is there a way around this?
Is there a way to use markdown within inlined LaTeX?
Is there a pure markdown solution?
Current versions of pandoc (i.e., pandoc 2.0 and later) supports fenced divs. Specially named divs are transformed into columns when targeting a slides format:
# This slide has columns
::: columns
:::: column
left
::::
:::: column
right
::::
:::
Pandoc translates this into the following LaTeX beamer code:
\begin{frame}{This slide has columns}
\protect\hypertarget{this-slide-has-columns}{}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
left
\end{column}
\begin{column}{0.48\textwidth}
right
\end{column}
\end{columns}
\end{frame}
This is simple and has the additional advantage of giving similar results when targeting other presentational formats like reveal.js.
More than two columns work out of the box for Beamer output. Powerpoint, however, only supports two columns. For reveal.js, the widths of three or more columns must be given explicitly:
::: columns
:::: {.column width=30%}
left
::::
:::: {.column width=30%}
middle
::::
:::: {.column width=30%}
right
::::
:::
The problem is that pandoc ignores markdown if it finds a \begin{}. An alternative is to edit the beamer template and add the following:
\newcommand{\columnsbegin}{\begin{columns}}
\newcommand{\columnsend}{\end{columns}}
And write it like this:
\columnsbegin
\column{.5\textwidth}
~~~~~~~~Python
>>> some python code
~~~~~~~
\column{.5\textwidth}
![](A_generated_image.pdf)
\columnsend
I hope still valuable. I made a Pandoc filter in Python to put columns easily, so you can write your presentations in this way:
# Hello World
[columns]
[column=0.5]
~~~python
if __name__ == "__main__":
print "Hello World"
~~~
[column=0.5]
This is how a "Hello World" looks like in Python
[/columns]
that the filter will convert each markup to \begin{columns} and \column{.5\textwidth}, so, the document above will turn in
\begin{frame}[fragile]{Hello}
\begin{columns}
\column{0.5\textwidth}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{some python code}
\end{Highlighting}
\end{Shaded}
\column{0.5\textwidth}
Hello World
\end{columns}
\end{frame}
The code filter is here
import pandocfilters as pf
def latex(s):
return pf.RawBlock('latex', s)
def mk_columns(k, v, f, m):
if k == "Para":
value = pf.stringify(v)
if value.startswith('[') and value.endswith(']'):
content = value[1:-1]
if content == "columns":
return latex(r'\begin{columns}')
elif content == "/columns":
return latex(r'\end{columns}')
elif content.startswith("column="):
return latex(r'\column{%s\textwidth}' % content[7:])
if __name__ == "__main__":
pf.toJSONFilter(mk_columns)
If you never use a pandoc filter, just save the filter to the same document location as columnfilter.py (or other name you want) and run
pandoc -t beamer --filter columnfilter.py yourDocument.mkd
And enjoy!
Beamer Specific Answer. I ran across a solution when attempting to add multiple columns for Pandoc in a regular document. It works here as well, though it does constrain you to Beamer; though that is your use case.
In the slide deck, insert once:
---
header-includes:
- \newcommand{\hideFromPandoc}[1]{#1}
- \hideFromPandoc{
\let\Begin\begin
\let\End\end
}
---
Then add content thus:
\Begin{columns}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\End{columns}
Creating the "hideFromPandoc" command lets you insert begin/end statements throughout without depriving you of markdown in the block.
Fenced Div Answer. There's an answer above that refers to fenced divs. I commented that the answer only works with two columns. It breaks down with more. Here is how that answer works with multiple divs:
::: {.columns}
:::: {.column width=0.3}
Test
::::
:::: {.column width=0.3}
Test
::::
:::: {.column width=0.3}
Test
::::
:::
To get this answer, I had to look at the commit that added the column feature specifically.
You could use FletcherPenney MultiMarkdown which can process markdown to LaTeX/Beamer. Compared to Pandoc, MultiMarkdown has not so many features. However, especially when working with LaTeX it has the advantage that you can embed LaTeX code directly into the Markdown in HTML comments.
Your code would look like this:
<!-- \begin{columns} -->
<!-- \column{.5\textwidth} -->
>>> some python code
<!-- \column{.5\textwidth} -->
![](A_generated_image.pdf)
<!-- \end{columns} -->
For me this solution works fine. With a good editor (e.g. Scrivener, Sublime Text) you can write the latex code without all the comments and find/replace them after editing. In addition, the Metadata support in Multimarkdown is much more flexible, so that it is easier to customize presentations.
In the meantime, I hope that the Pandoc team provides a solution to this problem. I think there are some users who would like to embed small LaTex code particles throughout their markdown documents without having them converted/escaped.
You can use MultiMarkDown comments ( "<!-- Your LaTeX Code inside -->" ) with Pandoc when you enclose the Pandoc command in which you transform your markdown to LaTeX with two sed commands.
In the first sed run, you change the MultiMarkDown comments to "\verb+AAAAAAALaTeX-StuffZZZZZZ+". Then you transform to LaTeX with Pandoc as usual, everything inside "\verb+AAAAAAALaTeX-StuffZZZZZZZ+" is left alone. Then you run sed on the TeX-File and delete the "\verb+AAAAAAA" and "ZZZZZZ+" unfolding your LaTeX code.
The first sed command line before the Pandoc transformation could look like this:
sed -E -e "s/<\\!--(.+)--\\>/\\\\verb\+AAAAAAA\1ZZZZZZZ\+/g " \
source.md > source.i.md
Then use Pandoc on source.i.md as usual to create source.tex. Second sed run like this:
sed -E -e "s/\\\\verb\+AAAAAAA(.+)ZZZZZZZ\+/\1/g" -i "" source.tex
I automated everything in a Makefile so that I can make more changes e.g. to table definitions in one step. On first glance this approach works fine (tested it on column definitions with the beamer class).
With this little sed scripts, you can use all the nice things from Pandoc. You need only to mmd-comment those TeX and LaTeX commands which become either escaped or enclose larger parts of your Markdown.
I want to use latex-style citations \cite{key} in my markdown so that I can create tex and pdf documents nicely using pandoc. However, when I cite something, it shows the keyword in brackets instead of the citation style, such as author name or citation number. In other words, I want it to show up in the PDF as "This is my citation [1]" but instead it is appearing as "This is my citation [mykey]". Also, my references list isn't showing up after I add my # References header. What is going on here?
Below is my sample command for producing this along with the sample files and my current incorrect output file (test.pdf).
pandoc test.md --biblatex --biblio test.bib --csl chicago-author-date.csl -o test.pdf
test.md
% My test pandoc-ument
I want to reference this: \cite{Gepasi1993}
# References
test.bib
#ARTICLE{Gepasi1993,
Author = {P. Mendes},
Journal = {Comput. Applic. Biosci.},
Pages = {563--571},
Title = {GEPASI: A software package for modelling the dynamics, steady states and control of biochemical and other systems.},
Volume = {9},
Year = {1993}
}
test.pdf
I want to reference this: [Gepasi1993]
The --biblatex option is not for writing biblatex directly in markdown.
What it does is convert native pandoc markdown citations, like
[#Gepasil1993, p. 5]
to biblatex citations in LaTeX output.
If you use pandoc markdown citations instead of the LaTeX ones, you'll
find that the citations work. Use this command:
pandoc test.md --biblio test.bib --csl chicago-author-date.csl -o test.pdf
with this input:
I want to reference this: [#Gepasi1993]
Pandoc's citation format is documented in the Pandoc User's Guide.
If you really want to use raw biblatex citations in your markdown input,
you can, but then you need to take care of the bibliography stuff
yourself. You'd do it this way:
pandoc test.md --parse-raw -t latex -s > test.tex
pdflatex test
biber test
pdflatex test
pdfltatex test
I have a little problem where I would like to insert a svn diff of a LaTeX document into
another LaTeX document, the goal is to show what has changed since revision XXX.
However since the diff contains a lot of LaTeX command I can't include it right into the document since LaTeX will interpit them and not just "print" them.
Today I have this in my Makefile
DIFF_INFO=diff.info.tex
DIFF_REV=167
diffinfo:
$(shell echo "\n" > $(DIFF_INFO) )
$(shell echo "\\section{diff $(DIFF_REV)} \n" >> $(DIFF_INFO) )
$(shell echo \\\\begin{verbatim} >> $(DIFF_INFO) )
$(shell svn diff --revision $(DIFF_REV) $(N).tex >> $(DIFF_INFO) )
$(shell echo \\\\end{verbatim} >> $(DIFF_INFO) )
And at the end of the LaTeX document I have this:
\IfFileExists{diff.info.tex}
{
\newpage
\input{diff.info.tex}
}
But this fails hard!
My next idea is to write a perl script that replaces all invalid chars with something that LaTeX can show, but it feels like I'm risking to reinvent the wheel so I figured that I could ask if someone had a better idea?
How do I include and show LaTeX code in the document?
Thanks
Johan
Update:
Thanks "unknown (google)" for pointing out verbatim, it did what I wanted it to.
Update:
I also looks like I should try that listings that las3rjock told us about since it look kind of nice.
Update:
Could not get listings to work in my case, I get some strange utf warnings about invalid chars. But the verbatim is working so I will use that way this time.
I second Boojum's recommendation in a comment to another answer that you use the listings package. For LaTeX code listings, I use settings that I found in André Miede's classicthesis package. Here is a sample document (quine.tex) and its output:
\documentclass[12pt,letterpaper]{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color}
% listings settings from classicthesis package by
% Andr\'{e} Miede
\lstset{language=[LaTeX]Tex,%C++,
keywordstyle=\color{RoyalBlue},%\bfseries,
basicstyle=\small\ttfamily,
%identifierstyle=\color{NavyBlue},
commentstyle=\color{Green}\ttfamily,
stringstyle=\rmfamily,
numbers=none,%left,%
numberstyle=\scriptsize,%\tiny
stepnumber=5,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
frame=single
%frame=L
}
\begin{document}
\lstinputlisting{quine.tex}
\end{document}
(click to enlarge)
There' a verbatim package that you can include with \usepackage{verbatim} and access using \verbatiminput{filename}.