]> git.lyx.org Git - lyx.git/commitdiff
Add an external template for minted
authorEnrico Forestieri <forenr@lyx.org>
Sun, 28 May 2017 21:43:19 +0000 (23:43 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 28 May 2017 21:43:19 +0000 (23:43 +0200)
See #9095

lib/Makefile.am
lib/examples/minted.lyx [new file with mode: 0644]
lib/xtemplates/minted.xtemplate [new file with mode: 0644]

index 48bef2bfdb1655f32475eb3e141db6230b7352a9..ca997e3c46800ade2d7c1dd64cb2d23c7fb786e8 100644 (file)
@@ -341,6 +341,7 @@ dist_examples_DATA = \
        examples/listerrors.lyx \
        examples/localization_test.lyx \
        examples/longsheet.gnumeric \
+       examples/minted.lyx \
        examples/modernCV.lyx \
        examples/MultilingualCaptions.lyx \
        examples/noweb2lyx.lyx \
@@ -2440,6 +2441,7 @@ dist_xtemplates_DATA = \
        xtemplates/gnumeric.xtemplate \
        xtemplates/inkscape.xtemplate \
        xtemplates/lilypond.xtemplate \
+       xtemplates/minted.xtemplate \
        xtemplates/pdfpages.xtemplate \
        xtemplates/raster_image.xtemplate \
        xtemplates/vector_graphics.xtemplate \
diff --git a/lib/examples/minted.lyx b/lib/examples/minted.lyx
new file mode 100644 (file)
index 0000000..02a36bb
--- /dev/null
@@ -0,0 +1,213 @@
+#LyX 2.3 created this file. For more info see http://www.lyx.org/
+\lyxformat 543
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin /systemlyxdir/examples/
+\textclass article
+\begin_preamble
+\usemintedstyle{bw}
+\usepackage{xcolor}
+\definecolor{lgray}{rgb}{0.95, 0.95, 0.95}
+\usepackage{eso-pic}
+\newlength{\boxwidth}
+\newlength{\boxheight}
+\setlength{\boxwidth}{\paperwidth}
+\setlength{\boxheight}{\paperheight}
+\addtolength{\boxwidth}{-1.2cm}
+\addtolength{\boxheight}{-2.5cm}
+\AddToShipoutPicture{%
+   \setlength{\@tempdimb}{0.5cm}%
+   \setlength{\@tempdimc}{1.0cm}%
+   \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
+     \hbox{\fboxrule=0.6pt\fbox{\vbox to \boxheight{%
+     \vss\hbox to \boxwidth{\hss}\vss}}}}%
+   \addtolength{\@tempdimc}{\boxheight}%
+   \addtolength{\@tempdimc}{6.5pt}%
+   \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
+     \hbox{\fboxrule=0.6pt\fcolorbox{black}{lgray}{\vbox to 3.5mm{%
+     \vss\hbox to \boxwidth{\hss\textbf{\textsf{\small\titlename}}\hss%
+     \hbox to 0pt{\hss\textsf{\footnotesize Page \arabic{page}/\pageref{lastpage}~}}}\vss}}}}%
+}
+\end_preamble
+\use_default_options true
+\maintain_unincluded_children false
+\language english
+\language_package default
+\inputencoding auto
+\fontencoding global
+\font_roman "times" "DejaVu Sans Mono"
+\font_sans "helvet" "DejaVu Sans"
+\font_typewriter "courier" "DejaVu Sans Mono"
+\font_math "auto" "default"
+\font_default_family default
+\use_non_tex_fonts true
+\font_sc false
+\font_osf false
+\font_sf_scale 95 95
+\font_tt_scale 110 110
+\use_microtype false
+\use_dash_ligatures true
+\graphics default
+\default_output_format pdf4
+\output_sync 0
+\bibtex_command default
+\index_command default
+\paperfontsize 12
+\spacing single
+\use_hyperref false
+\papersize default
+\use_geometry true
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation landscape
+\suppress_date false
+\justification true
+\use_refstyle 1
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\leftmargin 0.5cm
+\topmargin 1.35cm
+\rightmargin 0.5cm
+\bottommargin 1.05cm
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 0
+\math_numbering_side default
+\quotes_style english
+\dynamic_quotes 0
+\papercolumns 2
+\papersides 1
+\paperpagestyle empty
+\tracking_changes false
+\output_changes false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict false
+\end_header
+
+\begin_body
+
+\begin_layout Standard
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+This example shows a possible use of the minted package for typesetting
+ listings containing unicode characters.
+ For this reason, the default output format is 
+\family typewriter
+PDF (XeTeX)
+\family default
+.
+ The listing is typeset using the DejaVu font.
+ If this font is not installed on your system, you need choosing a different
+ one in Document\SpecialChar menuseparator
+Settings\SpecialChar menuseparator
+Fonts.
+\end_layout
+
+\begin_layout Plain Layout
+Other than the minted latex package, you also need the pygments python module.
+ See the minted documentation for directions on how to install it.
+ If you use a linux system, you can possibly install a suitable package
+ through your package manager.
+ Look for python packages named 
+\family typewriter
+python-pygments
+\family default
+ or similar.
+\end_layout
+
+\begin_layout Plain Layout
+Another required package is the 
+\family typewriter
+eso-pic
+\family default
+ latex package, so that you also need to install it.
+ It is used to draw a page frame around the listing.
+\end_layout
+
+\begin_layout Plain Layout
+Remember to add the -shell-escape option to the xelatex command in the Preferenc
+es\SpecialChar menuseparator
+File Handling\SpecialChar menuseparator
+Converters\SpecialChar menuseparator
+LaTeX(XeTeX)->PDF(XeTeX) converter.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+def
+\backslash
+titlename{lyxpak.py}
+\end_layout
+
+\end_inset
+
+
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+This the title of the listing.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset External
+       template MintedSource
+       filename ../scripts/lyxpak.py
+       display false
+       extra LaTeX "fontsize=\tiny,baselinestretch=1.05,frame=leftline,framesep=10pt,breaklines,breakanywhere,lang=python"
+       extra PDFLaTeX "fontsize=\tiny,baselinestretch=1.05,frame=leftline,framesep=10pt,lang=f77"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset CommandInset label
+LatexCommand label
+name "lastpage"
+
+\end_inset
+
+
+\end_layout
+
+\end_body
+\end_document
diff --git a/lib/xtemplates/minted.xtemplate b/lib/xtemplates/minted.xtemplate
new file mode 100644 (file)
index 0000000..7cc6535
--- /dev/null
@@ -0,0 +1,79 @@
+#
+# Minted External Template
+#
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+#
+# author Enrico Forestieri
+#
+# Full author contact details are available in file CREDITS.
+#
+# External templates expect to deal with commands of the form
+#   \command[options]{parameter}
+# while the \inputminted command has the form
+#   \inputminted[options]{language}{filename}
+#
+# In order to use the external templates machinery, the options of the
+# minted package are extended to be able to construct a proper \inputminted
+# command. This template defines an additional 'lang' option for minted, which
+# is then extracted from the options and passed as the second non-optional
+# parameter of \inputminted. This template works for minted version 2.1 or
+# higher. As it relies on the internals of minted, an update might break it.
+
+PreambleDef minted
+    \usepackage{minted}
+    \@namedef{minted@opt@cmd@lang}{latex}
+    \define@key{minted@opt@cmd}{lang}{\@namedef{minted@opt@cmd@lang}{#1}
+                                      \minted@configlang{#1}}
+    \DeclareRobustCommand\inputsource{\@ifnextchar[\@inputsrc{\@inputsrc[]}}
+    \def\@inputsrc[#1]#2{\inputminted[#1]{\minted@opt@cmd@lang}{#2}}
+PreambleDefEnd
+
+Template MintedSource
+    GuiName "Minted Source Code"
+    HelpText
+       Format source code using the 'minted' package.
+       This template works with minted version 2.1 or higher.
+       The source language is specified by the 'lang' option,
+       which must be inserted into the 'Option' field in the
+       'LaTeX and LyX options' tab.
+
+       Example options:
+       * linenos,fontsize=\footnotesize,lang=fortran
+       * bgcolor=yellow,baselinestretch=1.2,lang=c
+       * frame=lines,framesep=2\fboxsep,lang=python
+
+       If 'lang=xxx' is not given, 'lang=latex' is assumed by default.
+       Make sure to use the '-shell-escape' option for the latex backend.
+       Read the documentation of the minted package
+       for further options and details.
+    HelpTextEnd
+    InputFormat text
+    FileFilter "*"
+    AutomaticProduction true
+    Preview InstantPreview
+    Transform Extra
+    Format LaTeX
+       Preamble minted
+       TransformOption Extra ExtraOption
+       Option Arg "[$$Extra]"
+       Product "\\inputsource$$Arg{$$AbsPath$$Basename$$Extension}"
+       UpdateFormat text
+       UpdateResult "$$AbsPath$$Basename$$Extension"
+       ReferencedFile text "$$AbsPath$$Basename$$Extension"
+    FormatEnd
+    Format PDFLaTeX
+       Preamble minted
+       TransformOption Extra ExtraOption
+       Option Arg "[$$Extra]"
+       Product "\\inputsource$$Arg{$$AbsPath$$Basename$$Extension}"
+       UpdateFormat text
+       UpdateResult "$$AbsPath$$Basename$$Extension"
+       ReferencedFile text "$$AbsPath$$Basename$$Extension"
+    FormatEnd
+    Format Ascii
+       Product "$$Contents(\"$$AbsPath$$Basename$$Extension\")"
+       UpdateFormat text
+       UpdateResult "$$AbsPath$$Basename$$Extension"
+    FormatEnd
+TemplateEnd