TransWikia.com

Listing not fully filling background with escape inside

TeX - LaTeX Asked by Jundarer on August 30, 2021

I made this minimal example to showcase the problem I am having:

documentclass{article}
usepackage{xcolor}
usepackage{listings}
definecolor{background}{HTML}{EEEEEE}
definecolor{xmlOrange}{HTML}{cc7a00}
definecolor{xmlGreen}{HTML}{009900}

lstset{
    basicstyle=fontsize{9}{11}ttfamily,
    escapeinside={@~}{~},
    showstringspaces=true,
    breaklines=true,
    frame=lines,
    backgroundcolor=color{background},
    commentstyle=color{blue},
    morecomment=[s][color{xmlOrange}]{"}{"},
    morecomment=[s][color{xmlGreen}]{<!--}{-->},
}

newcommand{test}{{colorbox{background}{color{xmlOrange}{test Text}}}}

begin{document}

begin{lstlisting}
<root>
    <header test="@~test~">
    </header>
</root>
end{lstlisting}

end{document}

What you end with is this:

weird background

I have to make this way because the “test Text” is taken from a different from a command (this can’t be changed).

If I completely remove the colorbox it works as long as the text input to the listing via LaTeX code doesn’t cause a new line. Once this happens the entire line becomes white which looks even worse:

emtpy line

I tried a number of packages but they all seem to just be creating a boxes within the listing which doesn’t work for my case.

Update with external file:

Using

newtcbinputlisting{xmlListing}{colframe=background, colback=background, listing options={language=xml,columns=fullflexible},listing only }

and then using the previous example xml in a file called test.xml:

xmlListing{test.xml}

results in this:

input problem

One Answer

Thanks to Ulrike Fischer(and the docs+other answers found via it), solution was to simply create a newcbtinputlisting via

newtcbinputlisting{xmlListing}[1]{colframe=background, colback=background, listing options={language=xml,columns=fullflexible}, breakable, listing only,listing file={#1} }

and then using it with

xmlListing{filename}

Answered by Jundarer on August 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP