Hi all,

during creation of a Markdown converter in LyX I noticed some behavior,
which messes up the final output.

- created a new File Format 'Markdown' (as 'Document format' and 'With
  TeX fonts:' = 'PDF (XeTex)' <-- side note: using 'PDF (pdflatex)'
  would result in UTF-8 encoding errors during later conversion with
  pandoc error "pandoc: Cannot decode byte…")

- created a new Converter Definition 'LaTeX (XeTeX) -> Markdown', with
  converter command 'pandoc --wrap=none -f latex -t markdown -o $$o $$i'
  (results below are also the same when using 'LaTeX (plain) ->
  Markdown' as Converter)

- used this converter to export as Markdown


This basically works, and when I have an algorithm included in the LyX
file, the export still finishes, but has a fault in the output.

The intermediate .tex temp file created by LyX, during exporting to
markdown, has the two lines
--
\begin{lstlisting}%
[language=Python]
--
which in the final markdown file look like
--
    %
    [language=Python]
--
This causes problems when people receiving the Markdown file then try
to convert them to PDF, as the code is like that not correctly rendered
as program code.

When manually exporting the .lyx as 'PDF (XeTex)' the resulting file
does not have the problem, the output is one line
--
\begin{lstlisting}[language=Python]
--
which in the markdown file (generated using same command as in my new
LyX Converter: "pandoc --wrap=none -f latex -t markdown -o
"minimal-example.md" "minimal-example.tex") results in the correct
output, which gets handled as code:
--
``` {.python language="Python"}
--

This is Lyx 2.3.2 on Debian Linux and I would be happy if someone could
tell me how to get this generator running with the expected output of
algorithms.
[Attached example files, hoping the file names are self-explanatory]

TYVM,
Alexander

Attachment: minimal-example.lyx
Description: application/lyx

Minimal example

    %
    [language=Python]
    @my_decorator(foo, bar=baz)
    def dummy(arg):
        arr = arg
        out = pack.method(arr)
        return out

Attachment: minimal-example--by-lyx.md.pdf
Description: Adobe PDF document

Minimal example

``` {.python language="Python"}
@my_decorator(foo, bar=baz)
def dummy(arg):
    arr = arg
    out = pack.method(arr)
    return out
```

Attachment: minimal-example--by-pandoc.md.pdf
Description: Adobe PDF document

%% LyX 2.3.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[10pt,american,ngerman]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=1.5cm,rmargin=1.5cm}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
 breaklinks=true,pdfborder={0 0 0},pdfborderstyle={},backref=page,colorlinks=false]
 {hyperref}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}
\providecommand{\algorithmname}{Algorithmus}
\floatname{algorithm}{\protect\algorithmname}

\makeatother

\usepackage{listings}
\addto\captionsamerican{\renewcommand{\algorithmname}{Algorithm}}
\addto\captionsamerican{\renewcommand{\lstlistingname}{Listing}}
\addto\captionsngerman{\renewcommand{\algorithmname}{Algorithmus}}
\addto\captionsngerman{\renewcommand{\lstlistingname}{Listing}}
\renewcommand{\lstlistingname}{Listing}

\begin{document}
Minimal example

\selectlanguage{american}%
\begin{algorithm}[h]
\begin{lstlisting}[language=Python]
@my_decorator(foo, bar=baz)
def dummy(arg):
	arr = arg
	out = pack.method(arr)
	return out
\end{lstlisting}
\end{algorithm}
\selectlanguage{ngerman}%

\end{document}
\batchmode
\makeatletter
\def\input@path{{/dev/shm/}}
\makeatother
\documentclass[10pt,american,ngerman]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=1.5cm,rmargin=1.5cm}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
 breaklinks=true,pdfborder={0 0 0},pdfborderstyle={},backref=page,colorlinks=false]
 {hyperref}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}
\providecommand{\algorithmname}{Algorithmus}
\floatname{algorithm}{\protect\algorithmname}

\makeatother

\usepackage{listings}
\addto\captionsamerican{\renewcommand{\algorithmname}{Algorithm}}
\addto\captionsamerican{\renewcommand{\lstlistingname}{Listing}}
\addto\captionsngerman{\renewcommand{\algorithmname}{Algorithmus}}
\addto\captionsngerman{\renewcommand{\lstlistingname}{Listing}}
\renewcommand{\lstlistingname}{Listing}

\begin{document}
Minimal example 

\selectlanguage{american}%
\begin{algorithm}[h]
\begin{lstlisting}%
[language=Python]
@my_decorator(foo, bar=baz)
def dummy(arg):
	arr = arg
	out = pack.method(arr)
	return out
\end{lstlisting}
\end{algorithm}
\selectlanguage{ngerman}%

\end{document}
-- 
lyx-users mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-users

Reply via email to