# Converting LaTeX with citations to MediaWiki

I would like to convert my LaTeX paper to MediaWiki format in order to contribute parts of it to Wikipedia. The main difficulty is the citations. Here is a MWE LaTeX file:

\documentclass{article}
\usepackage[authoryear]{natbib}

\begin{document}
Over twenty years ago, \cite{McAfee1992Dominant} introduced the first
double auction mechanism.

\bibliographystyle{plainnat}
\bibliography{mwe}
\end{document}


And the matching BibTeX file:

@article{McAfee1992Dominant,
author = {McAfee, R. Preston},
title = {{A dominant strategy double auction}},
year = {1992}
}


The expected result should be something like this:

Over twenty years ago, McAfee<ref>{{Cite journal|author=R. Preston McAfee|title=A dominant strategy double auction|year=1992}}</ref> introduced the first double auction mechanism.


I tried to do the conversion using Pandoc:

pandoc -f latex -t mediawiki mwe.tex > mwe.wiki


But the citation did not appear in the result:

Over twenty years ago,  introduced the first double auction mechanism.


So I guess Pandoc does not support this kind of conversion.

Is there another tool/editor that can be used for this conversion?

You can use tex4ht with suitable configuration. I would use biblatex instead of natbib, because it gives us access to bibliographic fields. Your modified example:

\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\section{Hello world}

\subsection{Hello, hello}

Over \textit{twenty years} ago, \cite{McAfee1992Dominant} \textbf{introduced} the first
double auction mechanism.

\end{document}


I've added some more commands to illustrate my configuration examples. You can use following configuration for such file, named hello.cfg for example:

\Preamble{xhtml}

% remove html structure
\Configure{HTML}{}{}
\Configure{BODY}{}{}
\Configure{DOCTYPE}{}
\Configure{TITLE}{}{}
\Configure{VERSION}{}

\newcommand\starttag[1]{\NoFonts\HCode{#1}}
\newcommand\stoptag[1]{\NoFonts\HCode{#1}}
\newcommand\ConfigureInlinetag[2]{%
\Configure{#1}{\starttag{#2}}{\stoptag{#2}}%
}

\ConfigureInlinetag{textit}{''}
\ConfigureInlinetag{textbf}{'''}

\newcommand\ConfigureSection[2]{%
\Configure{#1}{}{}{\starttag{#2}}{\stoptag{#2\Hnewline}}%
}

\ConfigureSection{section}{==}
\ConfigureSection{likesection}{==}
\ConfigureSection{subsection}{===}
\ConfigureSection{likesubsection}{===}

% remove section id
\def\gobbleone#1#2{}

% remove <p> elements
\Configure{HtmlPar}{}{}{\HCode{\Hnewline}}{\HCode{\Hnewline}}

\DeclareFieldFormat[article]{entrytype}{Cite journal}
\DeclareFieldFormat*{titlecite}{{title=#1}}%
\DeclareFieldFormat*{yearcite}{{year={#1}}}%
\DeclareNameFormat*{labelname}{\ifthenelse{\value{listcount}=1}{#1}{}}
\DeclareCiteCommand{\cite}%
{\printnames{labelname}\HCode{<ref>}\{\{}%
{%
\printfield{entrytype}
\setunit{|}%
\printtext{author=}%
\printnames{author}%
\setunit{|}%
\printfield[titlecite]{title}%
\setunit{|}%
\printfield[yearcite]{year}%
}%
{}%
{\}\}\HCode{</ref>}}%

\begin{document}

\EndPreamble


there are some interesting things:

% remove html structure
\Configure{HTML}{}{}
\Configure{BODY}{}{}
\Configure{DOCTYPE}{}
\Configure{TITLE}{}{}
\Configure{VERSION}{}


with these configuration we remove all <html><head></head><body> stuff, so we get only clean text.

We need to configure all used commands which may produce html to produce either nothing, or mediawiki formatting. This is illustrated here:

\newcommand\starttag[1]{\NoFonts\HCode{#1}}
\newcommand\stoptag[1]{\NoFonts\HCode{#1}}
\newcommand\ConfigureInlinetag[2]{%
\Configure{#1}{\starttag{#2}}{\stoptag{#2}}%
}

\ConfigureInlinetag{textit}{''}
\ConfigureInlinetag{textbf}{'''}


With \ConfigureInlineTag we can set mediawiki tags for inline elements such as \textit. Similar configurations could be provided for section commands:

\newcommand\ConfigureSection[2]{%
\Configure{#1}{}{}{\starttag{#2}}{\stoptag{#2\Hnewline}}%
}

\ConfigureSection{section}{==}
\ConfigureSection{likesection}{==}
\ConfigureSection{subsection}{===}
\ConfigureSection{likesubsection}{===}


likesection is starred \section*.

Most complicated stuff is to configure \cite command to produce the output you want:

\DeclareFieldFormat[article]{entrytype}{Cite journal}
\DeclareFieldFormat*{titlecite}{{title=#1}}%
\DeclareFieldFormat*{yearcite}{{year={#1}}}%
\DeclareNameFormat*{labelname}{\ifthenelse{\value{listcount}=1}{#1}{}}
\DeclareCiteCommand{\cite}%
{\printnames{labelname}\HCode{<ref>}\{\{}%
{%
\printfield{entrytype}
\setunit{|}%
\printtext{author=}%
\printnames{author}%
\setunit{|}%
\printfield[titlecite]{title}%
\setunit{|}%
\printfield[yearcite]{year}%
}%
{}%
{\}\}\HCode{</ref>}}%


I haven't configured biblatex for some time, but this should print inline citation in format you want. Note that you should add

\DeclareFieldFormat[publication type]{entrytype}{publication info}


for each used publication type. Only article is supported by default, as I don't know what should be produced for other types.

make4ht -um draft -c hello.cfg filename
biber filename
make4ht -um draft -c hello.cfg filename


and you will get:

   ==Hello world==

===Hello, hello===

Over ''twenty years'' ago, McAfee<ref>{{Cite journal |author=McAfee, R. Preston|title=A dominant strategy double auction|year=1992}}</ref> '''introduced''' the first double auction mechanism.


in filename.html

I suggest to use HandWiki for creating Wiki articles. It uses MediaWiki but includes a BibTeX manager. This means you simply upload your BibTeX file to HandWiki, and use the same BibTeX key inside HandWiki o reference an article

You need to specify the bibliography in order to make it work:

pandoc -f latex -t mediawiki --bibliography=mediawiki.bib mediawiki.tex -o  mediawiki.wiki


You can also specify a CSL style to format the reference to your needs.

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 use

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

• The main differences are --metadata link-citations and cslstyle.csl, which enables you to process the citation in the format you want easily. Jan 25 '18 at 0:23