New answers tagged

4

Something like this perhaps? \documentclass{article} \usepackage[most]{tcolorbox} \begin{document} \begin{tcblisting}{listing only, listing options={language=tex},enhanced jigsaw, borderline={0mm}{1pt}{dashed,blue},sharp corners,,size=tight,fontupper={\tiny},boxrule=0pt,colback=white } \usepackage{color} \end{tcblisting} \end{document}


0

listings scans character by character, so you have to teach it not do do this in special cases: \documentclass{article} \usepackage{listings} \lstset{ language=Java, tabsize=2, numbers=left, basicstyle=\footnotesize, literate= {``}{\odblq}{1} {''}{\cdblq}{1}, } \newcommand{\odblq}{``} \newcommand{\cdblq}{''} \begin{document} \begin{...


1

You can get the curly left quotes with literate, but imho you have to disable the string delimiter to avoid to get the spaces shown. \documentclass{article} \usepackage{listings} \lstset{ language=Java, tabsize=2, numbers=left, basicstyle=\footnotesize, literate={``}{\textquotedblleft}1, deletestring=[b]", , } \begin{document} ...


2

So with tcolorbox you only need \usepackage[listings]{tcolorbox} ... \newtcblisting{testenv}{% colback=white,text side listing,boxrule=0pt,opacityframe=0} and that's it! \begin{testenv} Some lines? of \emph{text} !!! here. \end{testenv} produces


3

I find \tcbverbatimwrite from tcolorbox very convenient. It has support for listings as well and can be configured in multiple ways: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[most]{tcolorbox} \begin{document} \newenvironment{testenv}{% \begingroup% \tcbverbatimwrite{\jobname.tmp}}% {\endtcbverbatimwrite\endgroup% \noindent \...


1

If you want to use xelatex + luatex and unicode chars above position 256 you must add them to the process letter list. See The 'listings' package and UTF-8. In the case of the lambda you should add ^^^^03bb: \documentclass{standalone} %\usepackage{luatex85} %needed with newer luatex % allow unicode characters in listings \RequirePackage{fontspec} \...


3

Try this. Here, I use the accsupp package that allows, when creating the PDF, different things to be placed on the paper versus in the PDF "internal" document (used for copy/paste). The nice feature is that the text placed in the internal document from an AccSupp call is a single entity to the PDF and cannot be copy/pasted in part, but only in whole. ...


3

You may change the current language via the new command \entextcolor (using \foreignlanguage from babel): \documentclass[11pt,a4paper,xcolor=dvipsnames]{report} \usepackage[latin9]{inputenc} \usepackage[english,ngerman]{babel} \usepackage{listings} \usepackage[dvipsnames]{xcolor} \lstset{basicstyle=\footnotesize\ttfamily,frame=leftline,escapechar=@} \...


0

To have constant numbers follow the suggestion from Ignasi ans specify the firstnumber To specify to which occurrence of the label it should jump: \label<2>{lst:bar}. Of course this is not automatically the most recent occurrence, but for for simple constructs it might be enough. If you need to jump to both sides, you can use multiple labels \label<...


3

In your case better use of \newfontfamily\arabicfont[Script=Arabic, Scale=1.2]{Amiri} \newfontfamily\arabicfonttt{Courier New} Rather then \setmainfont[Script=Arabic, Scale=1.2]{Amiri} \setmonofont{Courier New} And you can remove bidi pachage which is loaded by default in case of RTL languages with polyglossia Code \documentclass[11pt, a4paper]{...


1

R syntax highlighting is defined in lstlang3.sty. The definition for R in that file contains the following: otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,_,/}, alsoother={._$}, If you want to remove the special treatment of _ then add something like this to your own definition of RStyle otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,...


1

The spacing in listings is determined by the column alignment (as described in section 2.10 of the documentation). So you can use the columns=fullflexible to achieve the look you want: \documentclass[ngerman,12pt,a4paper]{article} \usepackage{listings} \usepackage{url} \lstdefinelanguage{sparql} { morekeywords={LIMIT, PREFIX, GRAPH, AS, WITH, RECURSIVE, ...


2

I used morekeywords option instead of otherkeywords and you probably was loading the default predifined language by specifying \begin{lstlisting}[style=Python], as a first step you should define your listings language style (customize) by lstdefinestyle and then use it in the lstlisting environment as a style style=myPython. For the second part i am not ...


7

If you're willing to play around a bit, yes: \documentclass{article} \usepackage{listings} \lstset{ mathescape = true, basicstyle = \ttfamily} \newcommand{\dollar}{\mbox{\textdollar}} \begin{document} \begin{lstlisting} //basic instruction ["$\dollar$p.red"] $\rightarrow$ ["!jQuery", ".red"] \end{lstlisting} \end{document} We escape inside math ...


0

I've just begun experimenting with listings. Have you tried adding this line to your \lstset definition? breakatwhitespace=true, This setting determines whether automatic breaks should only happen at whitespace (I think by default they can happen anywhere in a line, to accommodate people who are writing types of code without much whitespace in it.) ...


3

Option caption enhances the listing with a caption, whose title is also used for the entry in the list of listings: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{language = Matlab, inputpath=./Code/} \begin{document} \lstlistoflistings \lstinputlisting[caption=test1.m]{test1.m} \lstinputlisting[caption=test2.m]{test2.m} ...


2

Since VnTeX uses vnr font by default, if you want your listing to use the same font, you can add fontfamily=vnr to minted options. This works for me. % !TeX encoding=UTF-8 \documentclass[12pt,a4paper]{article} \usepackage{fouriernc} \usepackage[utf8]{vietnam} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{hyperref} \usepackage{...


0

morecomment=[s]{=pod}{=cut} is the right way to go. In this case, were was an encoding-problem so that = was not an equals-sign, but something similar-looking.


2

This is a problem with the underlying listings package which gets problems when using utf8 characters. You could use \tcbuselibrary{listingsutf8} to relax the problem a little bit, because this maps the characters to a selectable 8-bit encoding (latin1 is the default). I do not know, if you can represent all Vietnamese characters in latin1, but I do not ...


1

i propose a solution using \minipage, the code may looks ugly if several lines are too long and will get wraped, so you must choose good parameters of both minipage width (consider the space between the two blocs; dont use 100% of the line width), image scaling scale and linewidth to obtain a nice shape. i hope i answreed your question. \documentclass{...


1

As Marijn said in his comment you should add alsodigit = {-} in your definition: \documentclass{report} \usepackage{listings} \lstdefinelanguage{powershell}{ alsodigit = {-}, keywords = {Get-AzureSubscription,Get-Host,anything} } \begin{document} \begin{lstlisting}[language=powershell] text anything Get-AzureSubscription \end{lstlisting} \end{...


0

Your code snippet is correctly colored: it starts with a " and therefore it is a string. A quick and dirty (actually not very quick yet considerably dirty) solution is to copy the html driver from lstlisting without the string delimiter, and add your own preferences: \documentclass{article} \usepackage{listings,xcolor} \definecolor{dkgreen}{rgb}{0,.6,0} \...


1

The idea for this comes from David Carlisle in chat. Basically, you put the listing in a box that will be scaled down if wider than some width. The adjustbox package provides an easy interface for doing just this. Note however, as Ulrike Fischer mentions in chat, that this may well end up looking horrible (such as my example below), but if looks are ...


4

Actually,it's the interaction of float and listings to prevent the correct (or desired behaviour) The following code is from listings \lst@UserCommand\lstlistoflistings{\bgroup \let\contentsname\lstlistlistingname \let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}% \tableofcontents \egroup} \@ifundefined{float@listhead}{}{% \...


3

Using a separate listing environment for shell-scripts with a specific name is quite easy, see the \lstnewenvironment code. More difficult is the splitting of the .lol and .los settings: \lst@MakeCaption must be redefined and changed to use los instead of lol. Please note: The current version does not work well with hyperref due to the anchors! \...


0

Okay after your guys help I figured it must be a package that screwed up my list of listings behavior/styling. After some debugging I found the package: the package float screws it up! MWE: \documentclass[12pt]{report} \title{List of listings problem} \author{Gerjan} \date{June 2016} \usepackage[english]{babel} % \usepackage{float} % Including this ...


4

Here is a solution. Use \setlength{\cftbeforetoctitleskip}{<dimen>} because \lstlistoflistings use \tableofcontents \documentclass{article} \usepackage{tocloft} \usepackage{listings} \setlength{\cftbeforetoctitleskip}{5cm} \begin{document} A \lstlistoflistings \begin{lstlisting}[caption={bla bla},label=list] for i:=maxint to 0 do begin { do nothing } ...


5

breakable inside a tabular does not seem very healthy as the tcolorbox most likely can't break at all. The disrupted box breaks apparently in as much boxes as have been used before, which is either a bug or tcolorbox sums up some pagegoal.



Top 50 recent answers are included