C++ 代码格式化

C++ 代码格式化

我在你的论坛上读了很多,而且读了很长时间。现在这是我的第一个问题。我在我的 latex 文档中包含了 C++ 代码,并且成功格式化了它。但有一个细节不起作用。我想用括号突出显示包含语句#include<**graphics.h>** 和#包括<**cmath.h>** 预定义颜色 MyMoreK 和带括号的三角函数sin(**角度))** 和cos(**角度)** 使用预定义颜色 MyTrigoFunctions。括号 [graphics.h/cmath.h/angle] 的内容应保留为绿色。我试了几天,但还是无法让它工作。希望你能帮助我!非常感谢你的帮助和建议!

德语中也一样:http://golatex.de/cundund-code-wie-kann-ich-noch-einzelne-worte-hervorheben-t18862.html

谨致问候,Spliffer

    \documentclass{scrartcl}
    \usepackage[T1]{fontenc}
    \usepackage[sfdefault]{AlegreyaSans}
    \usepackage[latin1]{inputenc}
    \usepackage[ngerman]{babel}

    \usepackage{xcolor}
    \usepackage{listings}
    \definecolor{MyString}{RGB}{101,138,186}
    \definecolor{MyKeyword}{RGB}{0,0,128}
    \definecolor{MyBackground}{RGB}{235,235,235}
    \definecolor{MyIdentifier}{RGB}{0,128,128}
    \definecolor{MyMoreK}{RGB}{49,128,255}
    \definecolor{MyTrigoFunctions}{RGB}{217,87,22}

    \lstset{
    %language=C++,
    %upquote=true,
    %columns=fixed,
    belowcaptionskip=1\baselineskip,
    breaklines=true,
    backgroundcolor=\color{MyBackground},
    %frame=L,
    xleftmargin=\parindent,
    showstringspaces=false,
    basicstyle=\small,
    breakatwhitespace=true,        
    breaklines=true,                
    keepspaces=false,          
    rulecolor=\color{black},
    keywordstyle=\bfseries\color{MyKeyword},
    stringstyle=\bfseries\color{MyString},
    commentstyle=\color{purple!80!black},%\itshape  
    identifierstyle=\color{MyIdentifier},%\bfseries
    %prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},  
    tabsize=1,  
    showtabs=false,
    emph={include},
    emphstyle={\color{MyMoreK}}
    }  
    %\lstset{style=MyCppStyle}

    \begin{document}
    \begin{lstlisting}[language=C++, caption={C++ code using listings}]

//#include<winbgim.h>


int SCREEN_W = 800;
int SCREEN_H = 200;


main(int argc, char*argv[])
{
initwindow(SCREEN_W, SCREEN_H);

setbkcolor(0);
cleardevice();

// Koordinaten für Kreis
int x, y;
const float  PI = 3.14159265358979f;
int length = 50;
float angle = 0.0;
float angle_stepsize = 0.1;

setcolor(15);
settextstyle(10, HORIZ_DIR, 2);

outtextxy(120, 20, "Circle_001 Kreis mit Sinus() und Cosinus(): ");

// go through all angles from 0 to 2 * PI radians
while (angle < 2 * PI)
{
// calculate x, y from a vector with known length and angle
x = length * cos (angle);
y = length * sin (angle);

putpixel((x + SCREEN_W/ 2) - 20 , (y + SCREEN_H/ 2) + 20 ,15);
angle += angle_stepsize;
}

while(!kbhit())
{
delay(1);
}

return 0;
}

\end{lstlisting}
\end{document}

相关内容