I have a "how to" document with hundreds of code listings. They do not follow standard language definitions in lyx's listings options, I have been trying to avoid doing the right-click on the listing to customize every little bit in the output.
I'd like to write a lyx layout file that has the 4 types of listings as environments or some other easy to choose way, and I'm a bit stumped on how to do it. I don't understand the FlexInset documentation in the Customize guide, but before I hammer on that, I need to make the plain old LaTeX markup work. I can't even make a successful LaTeX example using newenvironment. If you look below at my example document "ex.tex", you see I'm using a style file Sweavel, and I've attached that as well Sweavel provides the listings idioms in its own way, this works in ex.tex: \begin{Schunk} \begin{Sinput} A wopr example <- \end{Sinput} \end{Schunk} So, I think to myself, I'll just put that in an environment and access that from a LyX layout, but both latex and pdflatex can't process the file. Here is what I tried: In the preamble, add \newenvironment{whopr} {\begin{Schunk}\begin{Sinput}} {\end{Sinput}\end{Schunk}} Then use it \begin{whopr} some stuff \end{whopr} When I include those 3 lines, the compile just stops at an asterix. There's no error, it just dies like so: Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix <2008/02/07> (tvz)) (/usr/local/share/texmf/tex/latex/Sweavel.sty (/usr/share/texmf-texlive/tex/latex/graphics/color.sty (/etc/texmf/tex/latex/config/color.cfg) (/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def)) (/usr/share/texmf-texlive/tex/latex/ltxmisc/relsize.sty) (/usr/share/texmf-texlive/tex/latex/ae/ae.sty (/usr/share/texmf-texlive/tex/latex/base/fontenc.sty (/usr/share/texmf-texlive/tex/latex/base/t1enc.def) (/usr/share/texmf-texlive/tex/latex/ae/t1aer.fd))) (/usr/share/texmf-texlive/tex/latex/base/fontenc.sty (/usr/share/texmf-texlive/tex/latex/base/t1enc.def)) (/usr/share/texmf/tex/latex/R/tex/latex/upquote.sty (/usr/share/texmf-texlive/tex/latex/base/textcomp.sty (/usr/share/texmf-texlive/tex/latex/base/ts1enc.def)))) (./ex2.aux) (/usr/share/texmf-texlive/tex/latex/base/ts1cmr.fd) (/usr/share/texmf/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (/usr/share/texmf-texlive/tex/latex/listings/lstmisc.sty) (/usr/share/texmf-texlive/tex/latex/listings/lstlang1.sty) (/usr/share/texmf-texlive/tex/latex/listings/lstlang2.sty) (/usr/share/texmf-texlive/tex/latex/listings/lstlang3.sty)) * newenvironment will not cooperate with listings? It is not absolutely vital for me to do this with Sweavel in particular, but it does already provide the customized listings setup to do what I want. Schunk and Sinput are new environments in Sweavel, to save you trouble of looking at full attached style file, here's the meat: \newenvironment{Schunk}{}{} \lstnewenvironment{Sinput}{\lstset{style=Rstyle}}{} -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas
ex.tex
Description: TeX document
% Usage: \usepackage{Sweavel} % To change size of R code and output, use e.g.: \def\Sweavesize{\normalsize} % To change colors of R code, output, and commands, use e.g.: % \def\Rcolor{\color{black}} % \def\Routcolor{\color{green}} % \def\Rcommentcolor{\color{red}} % To change background color or R code and/or output, use e.g.: % \def\Rbackground{\color{white}} % \def\Routbackground{\color{white}} % To use rgb specifications use \color[rgb]{ , , } % To use gray scale use e.g. \color[gray]{0.5} % If you change any of these after the first chunk is produced, the % changes will have effect only for the next chunk. \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{Sweavel}{} % substitute for Sweave.sty using % listings package with relsize \RequirePackage{listings,fancyvrb,color,relsize,ae} \RequirePackage[T1]{fontenc} \IfFileExists{upquote.sty}{\RequirePackage{upquote}}{} \providecommand{\Sweavesize}{\smaller} \providecommand{\Rcolor}{\color[rgb]{0, 0.5, 0.5}} \providecommand{\Routcolor}{\color[rgb]{0.461, 0.039, 0.102}} \providecommand{\Rcommentcolor}{\color[rgb]{0.101, 0.043, 0.432}} \providecommand{\Rbackground}{\color[gray]{0.91}} \providecommand{\Routbackground}{\color[gray]{0.935}} % Can specify \color[gray]{1} for white background or just \color{white} \lstdefinestyle{Rstyle}{fancyvrb=false,escapechar=`,language=R,% basicstyle={\Rcolor\Sweavesize},% backgroundcolor=\Rbackground,% showstringspaces=false,% keywordstyle=\Rcolor,% commentstyle={\Rcommentcolor\ttfamily\itshape},% literate={<-}{{$\leftarrow$}}2{<<-}{{$\twoheadleftarrow$}}2{~}{{$\sim$}}1{<=}{{$\leq$}}2{>=}{{$\geq$}}2{^}{{$^{\scriptstyle\wedge}$}}1,% alsoother={$},% alsoletter={.<-},% otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},% escapeinside={(*}{*)}}% % Other options of interest: % frame=single,framerule=0.1pt,framesep=1pt,rulecolor=\color{blue}, % numbers=left,numberstyle=\tiny,stepnumber=1,numbersep=7pt, % keywordstyle={\bf\Rcolor} \lstdefinestyle{Routstyle}{fancyvrb=false,literate={~}{{$\sim$}}1{R^2}{{$R^{2}$}}2{^}{{$^{\scriptstyle\wedge}$}}1{R-squared}{{$R^{2}$}}2,% frame=single,framerule=0.2pt,framesep=1pt,basicstyle=\Routcolor\Sweavesize,% backgroundcolor=\Routbackground} \newenvironment{Schunk}{}{} \lstnewenvironment{Sinput}{\lstset{style=Rstyle}}{} \lstnewenvironment{Scode}{\lstset{style=Rstyle}}{} \lstnewenvironment{Soutput}{\lstset{style=Routstyle}}{} \lstnewenvironment{Sinputsmall}{% \lstset{style=Rstyle,basicstyle={\color{Rcolor}\small}}}{} \lstnewenvironment{Sinputsmaller}{% \lstset{style=Rstyle,basicstyle={\color{Rcolor}\smaller}}}{} \endinput