0

Hello from this question

C++ code, change the font

the first answer has given the code

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\colorlet{mygray}{black!30} \colorlet{mygreen}{green!60!blue} \colorlet{mymauve}{red!60!blue}

\lstset{ backgroundcolor=\color{gray!10},
basicstyle=\ttfamily, columns=fullflexible, breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{mygreen}, extendedchars=true,
frame=single,
keepspaces=true,
keywordstyle=\color{blue},
language=c++,
numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{blue}, rulecolor=\color{mygray},
showspaces=false,
showtabs=false,
stepnumber=5,
stringstyle=\color{mymauve},
tabsize=3,
title=\lstname
}

\begin{document}

\begin{lstlisting} #include <tesseract/baseapi.h> #include <leptonica/allheaders.h>

int main() { char *outText;

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api-&gt;Init(NULL, &quot;eng&quot;)) {
    fprintf(stderr, &quot;Could not initialize tesseract.\n&quot;);
    exit(1);
}

// Open input image with leptonica library
Pix *image = pixRead(&quot;/usr/src/tesseract/testing/phototest.tif&quot;);
api-&gt;SetImage(image);
// Get OCR result
outText = api-&gt;GetUTF8Text();
printf(&quot;OCR output:\n%s&quot;, outText);

// Destroy used object and release memory
api-&gt;End();
delete [] outText;
pixDestroy(&amp;image);

return 0;

} \end{lstlisting}

\end{document}

But when compiling the program in the printing part the output looks weird as below enter image description here

How do I remove that weird symbol between the letters?

주성우
  • 133

1 Answers1

2

listings supports explicitly showing spaces in strings. You can deactivate this using showstringspaces=false (see the line with <- ADDED):

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\colorlet{mygray}{black!30} \colorlet{mygreen}{green!60!blue} \colorlet{mymauve}{red!60!blue}

\lstset{ backgroundcolor=\color{gray!10},
basicstyle=\ttfamily, columns=fullflexible, breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{mygreen}, extendedchars=true,
frame=single,
keepspaces=true,
keywordstyle=\color{blue},
language=c++,
numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{blue}, rulecolor=\color{mygray},
showspaces=false,
showstringspaces=false, % <- ADDED showtabs=false,
stepnumber=5,
stringstyle=\color{mymauve},
tabsize=3,
title=\lstname
}

\begin{document}

\begin{lstlisting} #include <tesseract/baseapi.h> #include <leptonica/allheaders.h>

int main() { char *outText;

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api-&gt;Init(NULL, &quot;eng&quot;)) {
    fprintf(stderr, &quot;Could not initialize tesseract.\n&quot;);
    exit(1);
}

// Open input image with leptonica library
Pix *image = pixRead(&quot;/usr/src/tesseract/testing/phototest.tif&quot;);
api-&gt;SetImage(image);
// Get OCR result
outText = api-&gt;GetUTF8Text();
printf(&quot;OCR output:\n%s&quot;, outText);

// Destroy used object and release memory
api-&gt;End();
delete [] outText;
pixDestroy(&amp;image);

return 0;

} \end{lstlisting}

\end{document}

Result:

enter image description here

Skillmon
  • 60,462