I use listing typography C++ code, it performs very well when formatting LaTeX code, but it has very strange character output when used to typeset C++ code. Here is my WME:
\documentclass{standalone}
\usepackage{tcolorbox,listings}
\usepackage{listings}
\usepackage{tikz}
\usepackage{framed}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{comments}{HTML}{868686}
\definecolor{darkred}{RGB}{139,0,0}
\definecolor{darkblue}{RGB}{0,0,139}
\definecolor{chartreuse}{RGB}{127,255,0}
\definecolor{drakgreen}{RGB}{0,128,0}
\definecolor{lightgray}{RGB}{238,239,240}
\lstset{
language=C++,
keywordstyle=\color{darkblue},
basicstyle=\normalfont\ttfamily,
commentstyle=\color{comments}\ttfamily,
stringstyle=\rmfamily,
numbers=none,
numberstyle=\scriptsize,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
%frame=single,
captionpos=t,
belowcaptionskip=0em,
belowskip=0em
}
\lstdefinestyle{mystyle}{
language=C++,
extendedchars=true,
breaklines=true,
breakatwhitespace=true,
basicstyle=\ttfamily,
numbers=none
}
\tcbuselibrary{listings,skins,breakable}
\newtcblisting{code}{
arc=0mm,
top=0mm,
bottom=0mm,
left=3mm,
right=0mm,
width=\textwidth,
boxrule=1pt,
%colback=blue!20,
colback=lightgray,
listing only,
listing options={style=mystyle},
breakable
}
\begin{document}
\begin{code}
#include <iostream>
#include <fstream>
#include <functional>
#include <chrono>
using namespace std;
using namespace std::chrono;
int fib(int n) {
function<int (int,int,int)> iter;
iter=[n,&iter](int a,int b,int i) {
if(i>=n) {
return a;
}
else {
return iter(b,b+a,i+1);
}
};
return iter(0,1,0);
}
uint64_t count = 0;
uint64_t fibonacci(int n)
{
++::count;
if (::count - (::count >> 32 << 32) == 0)
cout << ::count << "\n";
//++::count;
if (n == 1 || n == 2) {
return 1;
}
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
\end{code}
\end{document}
Where is the problem?
No errors or warnings.The resulting list is:
(c.listing) [1
] (c.aux)
*File List*
standalone.cls 2018/03/26 v1.3a Class to compile TeX sub-files standalone
shellesc.sty 2016/06/07 v0.02a unified shell escape interface for LaTeX
ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO)
ifpdf.sty 2018/09/07 v3.3 Provides the ifpdf switch
ifxetex.sty 2010/09/12 v0.6 Provides ifxetex conditional
xkeyval.sty 2014/12/03 v2.7a package option processing (HA)
xkeyval.tex 2014/12/03 v2.7a key=value parser (HA)
standalone.cfg 2018/03/26 v1.3a Default configuration file for 'standalone'
class
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
tcolorbox.sty 2018/07/26 version 4.14 text color boxes
pgf.sty 2015/08/07 v3.0.1a (rcs-revision 1.15)
pgfrcs.sty 2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
trig.sty 2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg 2016/06/04 v1.11 sample graphics configuration
xetex.def 2017/06/24 v5.0h Graphics/color driver for xetex
pgfsys.sty 2014/07/09 v3.0.1a (rcs-revision 1.48)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK)
color.cfg 2016/01/02 v1.6 sample color configuration
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.1a (rcs-revision 1.1)
verbatim.sty 2014/10/28 v1.5q LaTeX2e package for verbatim enhancements
environ.sty 2014/05/04 v0.3 A new way to define environments
trimspaces.sty 2009/09/17 v1.1 Trim spaces around a token list
etoolbox.sty 2018/08/19 v2.5f e-TeX tools for LaTeX (JAW)
listings.sty 2018/09/02 1.7 (Carsten Heinz)
lstmisc.sty 2018/09/02 1.7 (Carsten Heinz)
listings.cfg 2018/09/02 1.7 listings configuration
tikz.sty 2015/08/07 v3.0.1a (rcs-revision 1.151)
pgffor.sty 2013/12/13 v3.0.1a (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
framed.sty 2011/10/22 v 0.96: framed or shaded text with page breaks
lstlang1.sty 2018/09/02 1.7 listings language file
lstlang1.sty 2018/09/02 1.7 listings language file
lstmisc.sty 2018/09/02 1.7 (Carsten Heinz)
pdftexcmds.sty 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO)
ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
c.listing
***********
)

^^Iindicates the problem is related to tab characters in your code. I can't reproduce the problem, though, even if I replace the spaces in your example by tabs. Perhaps try addingliterate={\^^I}{{}}4to your\lstdefinestyle{mystyle}options. – siracusa Nov 30 '18 at 04:18\lstdefinestyle{mystyle}and not to\newtcblisting{code}. I also get that error when I add it to the latter – siracusa Nov 30 '18 at 05:28-8bitflag (compile withxelatex -8bit). See also https://tex.stackexchange.com/questions/352063/listings-package-in-xelatex-every-tab-in-lstlisting-compiles-to-i-in-the-pd. – TeXnician Nov 30 '18 at 12:51