Tag Info

New answers tagged

3

You can add a morestring for these here statements. With the s option you can have a pair of delimiters, though this is not quite clear in the documentation: \documentclass[article]{memoir} \usepackage{listings} \lstset{language=Perl,stringstyle=\slshape} \begin{document} \begin{lstlisting}[morestring={[s]{<<HERE;}{HERE}}] my $commentA = ...


2

Place \clearpage before the listing, and all pending floats will be flushed before the listing starts.


0

You can break this using literate turning the - into a discretionary: \documentclass[twocolumn]{article} \usepackage{listings} \lstnewenvironment{code}[1][] { \lstset{ basicstyle=\ttfamily\footnotesize, breaklines=true, frame=lines, extendedchars=true, captionpos=b, caption=#1, literate={-}{-}{1\discretionary{-}{-}{}} } } ...


1

listings needs a 'hint' if the package should interprete $-$ as math content otherwise it's taken verbatim. The hint is the mathescape=true option to the lstlisting environment. \documentclass[12pt]{article} % For MATLAB code \usepackage[framed]{matlab-prettifier} \usepackage[T1]{fontenc} \lstMakeShortInline[style=Matlab-editor]" % For inline shortcut ...


9

I can reproduce the problem when the document class is specified in brackets [...] instead of braces {...}. \documentclass[article] \usepackage{listings} The terminal shows This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex) restricted \write18 enabled. entering extended mode (./bosh.tex LaTeX2e <2014/05/01> ...


3

You cannot use two source listings within a tcblisting, but you can put two listings side by side into a tcolorbox: \documentclass{article} \usepackage[skins,listings]{tcolorbox} \begin{document} \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,sidebyside] \begin{lstlisting}[style=tcblatex] Listing A some code \end{lstlisting} ...


4

You can define (for ease of use and re-use) a \srcsize command that sets an arbitrary font size (here 5pt for example) \makeatletter \newcommand{\srcsize}{\@setfontsize{\srcsize}{5pt}{5pt}} \makeatother and then in the style, you can use to set the size for the basic style: basicstyle={\ttfamily\srcsize} (adapt for other font families)


0

Use \begin{lstlisting}[columns=flexible] 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 \end{lstlisting}


1

This is not really an answer to your question, but a case against your approach; if you take heed of it, your problem will become irrelevant. Don't rely on listings to introduce syntactically correct line breaks My understanding is that you're typesetting MATLAB listings and you want the line-continuation token (...) to be introduced wherever listings' ...


0

Replace \only<1>{...} by \begin{onlyenv}<1>...\end{onlyenv} to use verbatim code inside: \documentclass[smaller]{beamer} \usepackage{graphicx} \usepackage{color,xcolor} \usepackage{boxedminipage} \usepackage{listings} \usepackage{pgf,pgfpages} \usepackage{tikz, subfig} \usetikzlibrary{arrows,shapes,positioning} \usetheme{boxes} ...


2

Just replace \only<1>{...} by \begin{onlyenv}<1>...\end{onlyenv}. Here: \documentclass{beamer} \usetheme[height=7mm]{Boadilla} \usepackage{listings} \begin{document} \begin{frame}[fragile] \frametitle{Brokenframe} \begin{columns}[c] \column{0.25\textwidth} \column{.5\textwidth} \centering ...


4

Option frame=leftline: \documentclass{article} \usepackage{listings} \begin{document} \lstset{numbers=left,frame=leftline} \begin{lstlisting} \usepackage{xifthen} \makeatletter %JB Taken from tufte-common.def \newcommand{\plainauthor}{}% \newcommand{\thanklesspublisher}{}% \newcommand{\thanklessauthor}{}% \renewcommand*{\author}[2][]{% ...


5

The listings package categorizes characters in three ways: letter, digit, and other. The R language for listings, whose definition can be found in lstdvrs.dtx, is defined in such a way as to treat periods as other: \lst@definelanguage{R}% %... alsoother={._$},% %... }% However, as I understand it, in R, a period (.) can be used in identifiers ...


1

This adds an extra brace group to make the box setting in \lst@DeInit "color safe" then removes \normalcolor as egreg mentioned in comments. Seems to work on this example.. \documentclass[a4paper]{book} \usepackage[T1]{fontenc} \usepackage{color} \usepackage[ hang, small, it, hypcap=true ]{caption} \usepackage{fancyvrb} \usepackage{listings} ...


2

If you are willing to create the verbatim component in advance of the listing, this can be done... If you need more than one verbatim block per listing, the myverbbox environment allows you to give names to the verb-boxes (rather than the default \theverbbox as shown here). \documentclass{article} \usepackage{listings}% http://ctan.org/pkg/listings ...


5

Yes, I would recommend you use \lstinline so that the same style is applied: Note that even though it appears the formatting is the same, if you look carefully you will notice that the spacing of the keywords in the \lstinline is slightly different than the listings. The reason for that is that the default for \lstinline as per the documentation is that ...


5

You can do something like the following, what you need is the internallinenumbers macro: \documentclass{article} \usepackage{tcolorbox} \usepackage{lineno} \begin{document} \begin{tcolorbox}[middle=0mm,boxsep=0mm] \setlength\linenumbersep{1cm} %sets the distance of the line numbers from the margin \begin{internallinenumbers} \begin{itemize} ...


3

\documentclass{IEEEtran} \usepackage{listings,multicol} % <--- multicol only required, if the multicols= option shall be used \usepackage{filecontents} % <--- only needed to provide example code \usepackage{lipsum} % <--- only needed to provide dummy text \lstset{language=Java, basicstyle=\ttfamily\footnotesize} ...


1

Until now I didn't find a way to make a listing span two colums using the command that reads the code from a file (\lstinputlisting). However, I managed how to do it by putting the code in the latex document, as follows: \begin{lstlisting}[float=*] code goes here \end{lstlisting}


4

If you must do this, it is possible with tikzmark. But watch out that you choose an appropriate escape character, which is never used in the listing itself. I would not recommend it though. It requires manual edits to your listing source, which may or may not be feasible, depending on the length of the listing. There are also better, clearer ways to explain ...


1

This is an attempt, but I am not sure what the OP really requires. \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{listings} \begin{document} \begin{tcblisting}{listing only,arc=0mm,auto outer arc} \documentclass[<options>]{<documentclassname>} \begin{document} \tableofcontents \chapter{section} \end{document} \end{tcblisting} ...


0

$\texttt{\textbackslash}\overbrace{\texttt{documentclass[<options>]}}^{\textrm{above text}}\underbrace{\texttt{\{<options<\}}}_{\textrm{below text}}$ Next time post a better quality image, please. EDIT: after your edit, I think you can't mix math mode and listing environments... Mine is a workaround.


0

To typeset code in a document, use the listings package. To have sections in appendices, just use \section as you normally would; they will automatically be numbered as A.1 etc.


3

We now have an Environment (with xparse, but not necessary) that lets everything we need to look like article. Hardest part were the equation nubers because of the lacking beamer font template. You haveto use ~ for the white space in the beamer template names. \makeatletter \NewDocumentEnvironment {EmulateArticle} {} { %Roman Font: \rmfamily ...


20

You can adjust the in and out angles as well as shift the location of the start and end points: Notes: I also added basicstyle=\ttfamily to have a more listings like output. A \tikzmark was added on the left and right of each mark to simplify the computations of the midpoints. Code: \documentclass[11pt]{article} \usepackage{listingsutf8} ...


4

The problem is the \underbar command in your moredelim setting: With unicode-math it is a math command. You could use e.g. the ulem package and \uline instead: \usepackage{ulem} ... `moredelim=[is][\uline]{_}{_},`


3

As far as I know, tabu doesn't support listings even in the tabu* environment. However, I found that pythontex works: \documentclass[11pt]{article} % use larger type; default would be 10pt \usepackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX) %%% PAGE DIMENSIONS \usepackage{geometry} % to change the page dimensions \geometry{a4paper} ...


3

Use caption={[Short caption]Very long and frustrating caption that noone want to see before this page} Full code: \documentclass[11pt,a4paper]{article} \usepackage{listings} \usepackage{color} \usepackage{courier} \definecolor{dkgreen}{rgb}{0,0.6,0} \definecolor{gray}{rgb}{0.5,0.5,0.5} \definecolor{mauve}{rgb}{0.58,0,0.82} ...


0

To clarify more, the issue was: the generated list of listings is included in the ToC as Contents instead of List of Listings. The solution is: as a first step is adding \renewcommand\lstlistlistingname{List of Listings} in the preamble to change the name from being Contents to List of Listings, inside the document (after \begin{document}) just include ...


2

A bit of hacking is required; see below. \documentclass{article} % the following two packages are for bold typewriter font \usepackage[T1]{fontenc} \usepackage{beramono} \usepackage{listings} \usepackage{xcolor} \lstdefinelanguage{iCli}{ comment = [l]{\%}, literate = \#{{\processhash}}1, %<-- required for bold prompt ...


3

While listings provides the key-value numberfirstline (set to false by default), it doesn't seem to deliver on the promise of not numbering the first line. As such, the following is work-around: Start "numbering" from 0 and check when printing the number whether it should be printed or not using a conditional. \documentclass{article} \usepackage{listings} ...


2

Add firstline=2 in the \lstset. \lstset{language=Java, firstline=2, numberstyle=\scriptsize, numbers=left, numbersep=5pt, numberblanklines=false, captionpos=b, basicstyle=\small\sffamily, columns=fullflexible, xleftmargin=16pt, frame=leftline, breaklines=true, tabsize=2, ...



Top 50 recent answers are included