2
votes
2answers
50 views

Counters for Chapter and Section environments when using tcolorbox for listings

This is a followup question of this question. With my MWE I'm getting wrong Listing numbers, wrong toc (including Chapter and Section environments from listings) and wrong bookmarks in pdf toc. Any ...
2
votes
1answer
61 views

Reading code from external file in tcolorbox and getting pdflatex> ! paragraph ended before \tcb@set@label was complete

I want to read code from external file in tcolorbox in new defined \texexptitled environment but could not succeeded (See MWE). Without this my MWE also throws two other errors pdflatex> ! ...
3
votes
1answer
55 views

listings using tcolorbox package without Chapter and Section environment effects

I want to get listings using tcolorbox package but without counting Chapter and Section environments. See in MWE, I used section environment withing listings which effects the counter for following ...
3
votes
0answers
43 views

Define new command which insert environment [duplicate]

Am i able to do something like this: (without defining new environment) \newcommand{\code}[2] { \begin{lstlisting}[language=#1] #2 \end{lstlisting} } I don't want to write: ...
5
votes
0answers
36 views

How can I make a custom environment that wraps listings?

Thanks to this answer, I know it is possible to float and wrap text around a listing. I would like to setup an environment for mini-code snippets that always floats and wraps the same way. I can ...
4
votes
1answer
70 views

Listings environment within another environment

\newtheorem{alg}{Algorithm}[subsection] \begin{alg}\label{alg:1} \begin{lstlisting}[frame = single, breaklines = true, numbers = left] test code \end{lstlisting} \end{alg} How can I prevent the ...
3
votes
1answer
145 views

Environment for two columns with lstlistings

In order to reduce copy-pasting, I want to create an environment that will produce a two-column table with headers and two listings in different languages, like below: \begin{tabular}{l l} Python ...
7
votes
1answer
97 views

Two block commands in \newenvironment [duplicate]

What is wrong with following document? \documentclass{article} \usepackage{xepersian} \usepackage{verbatim} \newenvironment{code} {\begin{latin}\begin{verbatim}} {\end{verbatim}\end{latin}} ...
4
votes
1answer
154 views

How to wrap floated minted listing in my own environment?

Here's what I'd like to do: \begin{code}{c}{Hello World in C}% I would prefer the caption to be optional #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ...
10
votes
1answer
300 views

How to force lstlisting caption names and numbers to always appear, even when captions are empty?

I noticed lstlisting environment seems to supress the caption name and number when no caption is specified. See the code below: \documentclass{article} \usepackage{listings} \lstset{language=C} ...
4
votes
1answer
216 views

Combining newenvironment, quote and lstlisting (mcode)

I am trying to combine various packages and commands with PdfLaTeX (through MikTex on MS Windows), including newenvironment, quote, mcode and lstlisting, to create an environment to define multiple ...
13
votes
2answers
156 views

Filecontents and newenvironment issue

I need to write some inlined code on an external file, then load it with listings. I would like to define a new environment, but if I do, filecontents does not save the first line of code (see MWE): ...
7
votes
1answer
408 views

defining a centered shadowboxed listings environment

I'm trying to define a environment for code listings wrapped in a shadowbox and centered in the line. Using this code, I can generate the kind of output that I want: ...
5
votes
1answer
134 views

compilation error in creation of new command

I'm trying to manipulate a bit an environment that I've found in internet, in GUIT forum. This is the minimal example ...
1
vote
1answer
129 views

Use Listing in newenvironment

I am trying to do a new environment or command (i tried both) where i can put in the name, description and code of a Method in c++ and it gives me a new section with the MethodName, the code listed ...
3
votes
1answer
180 views

How to combine framed and listings packages in new environment

I always use this LaTeX code to display a source code in my article. \begin{listingbox}{VB style} \begin{singlespace} \begin{lstlisting}[style=BASIC] Private Sub Form_Load() Dim tex As String ...
2
votes
1answer
2k views

Environment lstlisting undefined

Hi I have installed the listings package in order to display my code. I am running the following code within my document: \begin{lstlisting} public static void main(String[] args) { ...
8
votes
2answers
546 views

Combining `tikzpicture` and `lstlisting`

I'm working on a custom lstlisting environment, in which I use TikZ to add a frame and a title. Because of the widespread curly braces of node I cannot use newenvironment, so I have to resort to ...
4
votes
1answer
249 views

Multiple caption names for listings code (lstinputlisting) based on type of code

In my document I have used: \renewcommand\lstlistingname{Algorithm} \renewcommand\lstlistlistingname{Algorithms} to rename my lstlistings titles. The problem is that now I want to add a different ...
6
votes
1answer
815 views

lstlisting in a newenvironment

I have a problem with the lstlisting package. I want to define an \newenvironment with one obligatory parameter, which will be the caption name for the lstlisting. I will also have other lstlisting ...
4
votes
1answer
686 views

Creating a custom environment

I'm using the following syntax for my code snippets \begin{minipage}{\textwidth} \begin{lstlisting}[caption=<something>, label=<something>] The REST Endpoint URL is ...
6
votes
1answer
64 views

`advise` Environment in listings package

I was reading the documentation for the latex listings package and there are advises in it which look like so: I had a quick look in the source code for the documentation and it turns out that ...
7
votes
2answers
306 views

How can I define a custom listing environment?

I am trying to define an enviroment for a specific programming language, F#. Here's my code: \definecolor{bluekeywords}{rgb}{0.13,0.13,1} \definecolor{greencomments}{rgb}{0,0.5,0} ...
6
votes
2answers
2k views

Create a \lstnewenvironment that creates named listings

I am using the \lstnewenvironment to format a set of code listings in my document. \lstnewenvironment{code} {\lstset{language=haskell, basicstyle=\small\ttfamily, numbers=left, ...
5
votes
1answer
2k views

lstinputlisting does not include file within lstnewenvironment?

I want to use lstinputlisting to include a file with code within an lstlisting block, which is defined through a new environment. However, the lstinputlisting command itself, not the code, is ...
4
votes
2answers
427 views

Problems When Escaping from Listings

I would like to use LaTeX to document my C++ code, since I am able to typeset mathematics easily, as well as create diagrams using TikZ. I made a minimal LaTeX template for testing, but I have already ...
1
vote
1answer
176 views

Combine listings package with my own enviroment [duplicate]

Possible Duplicate: How to use different lstset settings for listings? I have defined my own enviroment as: \newenvironment{codegui}[3]{% \def\tmplanguage{#1}\relax ...
4
votes
1answer
326 views

Using LaTeX listings throughout the document

I've got a LaTeX document with a main file and many sub-files. Because we're writing a documentation we use code snippets everywhere. How can I define a listing and use it throughout the documents? ...
9
votes
3answers
418 views

Masking \end{lstlisting}

I am not sure if I am using the right wording in title. Basically what I need is to add the following source using the listing package. In preamble: \usepackage{listings} then and is here when I ...
4
votes
1answer
826 views

\newenvironment fails with special listings environment

I want to use the showexpl, but define a new environment with predefined settings. But all I get is an emergency stop. \documentclass{scrbook} \RequirePackage{showexpl} ...
1
vote
1answer
374 views

Why does pdfLaTeX fail when I try to use `begin{lstlisting}` inside a user-defined environment?

I'm having trouble with the listings package. I can't compile the following minimal example through pdfLaTeX: \documentclass[a4paper, 11pt, twoside, openright, english]{memoir} \usepackage{listings} ...
4
votes
2answers
1k views

newenvironment/newcommand for existing environment in LaTeX-Beamer

I would like to have the solution of highlighting a line in listings-package as a command or environment. To bad I cannot get it working. I tried: a simple newenvironment: compile errors ...
4
votes
1answer
715 views

Wrap latex environment

I'm a beginning latex user. I have some programming code in my document which I format using the lstlisting environment from the package listings. However this still allows the code segments to be ...
8
votes
1answer
2k views

How to define a new environment with a fancy box (tikz) around sample source-code (listings)?

This is what I want to do: \documentclass{beamer} \begin{document} \begin{frame}[fragile]{Frame 1} Some \structure{Python} code here: % I want to define a new "pythoncode" environment, so ...
1
vote
1answer
244 views

How to make my unusual environment accept one argument?

I cannot find a good title to express my question. Therefore, please parse the following code first. Minimal Code \documentclass[dvips,dvipsnames,cmyk,table]{book} ...
1
vote
1answer
411 views

Listings: new environments with arguments

I have this basic question. How can use arguments with listings? I tried this and it doesn't work: \lstnewenvironment{cor}[2][] {\linerange{#1-#2},\lstset{language=[Sharp]C,,basicstyle=\scriptsize, ...
10
votes
2answers
2k views

Listings: different counters for different listing environments

How do I create two lstlisting environments that each have its own counter? If I use for example \lstnewenvironment{algorithm}[2]{ \renewcommand\lstlistingname{Algorithm} \lstset{ ... } } ...