我正在寻找一个编辑器来打印(在纸上)C++ 代码。我目前在工程学校,讲师要求我们提交纸上的代码。
他要姓名+姓氏,班级编号(在标题上),底部的页码,以及每一页加粗的保留字!
在 Windows 上,它可以通过notepadd++. 但我在 Linux 上,我还没有找到有效的 IDE 或文本编辑器。(我已经试过了SCITE, gedit, 和Syntaxic)
ter*_*don 76
好吧,如果您想加倍努力,请在 LaTeX 中进行并提供专业级的 PDF 文件。你还没有提到你的发行版,所以我会给出基于 Debian 的系统的说明。不过,相同的基本思想可以在任何 Linux 上完成。
安装 LaTeX 系统和必要的包
sudo apt-get install texlive-latex-extra latex-xcolor texlive-latex-recommended
Run Code Online (Sandbox Code Playgroud)report.tex使用以下内容创建一个新文件(称为):
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
%% Define your header here. 
%% See http://texblog.org/2007/11/07/headerfooter-in-latex-with-fancyhdr/
\fancyhead[CO,CE]{John Doe, Class 123}
\usepackage[usenames,dvipsnames]{color}  %% Allow color names
%% The listings package will format your source code
\usepackage{listings}
\lstdefinestyle{customasm}{
  belowcaptionskip=1\baselineskip,
  xleftmargin=\parindent,
  language=C++,
  breaklines=true, %% Wrap long lines
  basicstyle=\footnotesize\ttfamily,
  commentstyle=\itshape\color{Gray},
  stringstyle=\color{Black},
  keywordstyle=\bfseries\color{OliveGreen},
  identifierstyle=\color{blue},
  xleftmargin=-8em,
  showstringspaces=false
}        
\begin{document}
\lstinputlisting[style=customasm]{/path/to/your/code.c}
\end{document}
Run Code Online (Sandbox Code Playgroud)
只需确保/path/to/your/code.c在倒数第二行进行更改,使其指向 C 文件的实际路径。如果要包含多个文件,请为另一个文件添加一个\newpage,然后再添加一个新\lstinputlisting文件。
编译 PDF(这会创建report.pdf)
pdflatex report.tex    
Run Code Online (Sandbox Code Playgroud)我使用我在此处找到的示例文件在我的系统上对此进行了测试,它创建了一个如下所示的 PDF:
有关将自动查找目标文件夹中的所有 .c 文件并在单独的部分中创建索引 PDF 文件的更全面的示例,请参阅我在此处的回答。
Use*_*ess 29
我通常会使用 enscript: 类似的东西
$ enscript --highlight=cpp
           --header='|Real Name|Class 101'
           --footer='|Page $% of $=|'
           -poutput.ps *.cpp
Run Code Online (Sandbox Code Playgroud)
将是一个开始 - 这会将 postscript 输出写入output.ps,因此您可以在修改配置时预览和覆盖它,然后在您满意后打印它。有关更多非常广泛的选项,请参阅手册页。
编辑让页脚正常工作对 enscript 来说有点痛苦 - 我从来没有注意到,因为我从来没有需要它。如果您将此文件保存到~/.enscript/so.hdr(您可能需要创建目录),您实际上将获得所需的输出
$ enscript --highlight=cpp
           --header='|Real Name|Class 101'
           --footer='|Page $% of $=|'
           --fancy-header=so
           -poutput.ps *.cpp
Run Code Online (Sandbox Code Playgroud)
给予
大致,
:hardcopy命令很简单,但不够灵活,而且小智 9
您可以:TOhtml在 vim 中使用该命令。这会将您所看到的(即语法突出显示)呈现为 html。从那里,可以打印为 pdf 的网络浏览器可以工作,因为您通常可以自定义页眉/页脚内容。
这可能类似于:hardcopyUseless 提到的命令,但我现在无法在我的系统上进行验证。
另一种可能性是从 QtCreator 打印,但似乎没有设置页眉/页脚的方法。