如何格式化研究报告中的代码

发布于 2024-08-25 13:22:04 字数 1431 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

南风起 2024-09-01 13:22:04

好吧,这取决于您的论文编写时要遵循哪种风格指南...

通常代码应该以单色字体编写,以便于阅读(例如 Lucida Sans Console 或 Courier New)。这意味着所有字母在页面上占据相同的空间。

当我编写用于发布的内容时,我将代码从侧面缩进 2.5 厘米,并以 Lucida Sans Console 字体为其提供浅灰色背景...遵循 C 样式代码缩进。

我会问您的机构是否有风格指南,但由于您缺乏这种能力,因此请使用流行的风格指南(例如哈佛系统),并确保自始至终遵循相同的格式。

以下是来自 Google Scholar 的显示风格的期刊列表:
http://scholar.google.com.au/scholar?hl=en&q=PHP+SQL+programming+journal&btnG=Search&as_sdt=2000&as_ylo=&as_vis=0

Well it depends on which style guide your paper is being written to comply to...

Usually code should be written in a monotype font so that it is easily readable (E.g. Lucida Sans Console or Courier New). This means that all letters take up the same space on the page.

When I have written bits for publishing I have indented the code 2.5cm from the side and given it a light grey background, in a Lucida Sans Console font... Following C style code indenting.

I would ask your institution if they have a style guide, but as you have a lack of this ability go with a popular style guide such as the Harvard system and make sure you follow the same format throughout.

Here is a list of journals from Google Scholar which display style:
http://scholar.google.com.au/scholar?hl=en&q=PHP+SQL+programming+journal&btnG=Search&as_sdt=2000&as_ylo=&as_vis=0

如痴如狂 2024-09-01 13:22:04

这是我的偏好:

在内联编写时,去掉与解释无关的代码(例如 import
如前所述的语句,但也可能是“显而易见的”变量声明等)。内联放置代码的目的应该是为了与描述该代码块的段落轻松交叉引用。

附录中的代码应该是完整的(如 - 您可以将其放入编译器中并按“执行”)。

不要害怕将大量删减的代码放入片段中,并引用包含完整代码的附录 - 附录代码供某人单独阅读/运行。内联代码供人们浏览并帮助理解该部分的具体要点。

This is my preference:

When writing inline, get rid of code that is irrelevant to the explanation (such as import
statements as previously mentioned, but potentially also variable declarations that are "obvious" and the like). The goal of code placed inline should be for easy crossreference with the paragraph describing that code block.

Code placed in appendices should be complete (as in - you can put this into your compiler and press go).

Don't be scared of placing heavily cut down code in snippets, along with a reference to the appendix containing the full code - the appendix code is for someone to read/run separately. the inline code is for people to glance at and help understand the specific point of that section.

梦情居士 2024-09-01 13:22:04

我想说的是具有标准文本间距和标准行间距的 Courier 字体,全黑文本,适当的缩进。

就代码本身而言,省略import语句、注释就可以了。您可能需要在代码中内嵌添加脚注,例如 {1}、{2},作为注释并在下面解释代码的文本中引用。

本文第 6 页有一个示例:

http:// /www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf

I would say Courier font with standard text spacing and standard line spacing, all black text, proper indentation.

In terms of the code itself, omit import statements, comments are okay. You may want to add foot notes like {1}, {2}, inline in the code as a comment and reference below in the text that explains the code.

This paper has an example on page 6:

http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf

笑,眼淚并存 2024-09-01 13:22:04

我意识到这是一个老问题,但不要忘记对代码中的行进行编号!对于单行文字来说,跳过数字是可以的,但是对于更大的数字,它们几乎是必需的。

I realise that this is an old question, but do not forget to number the lines in your code! For one-liners, it's okay to skip numbers, but anything larger, they're almost required.

岁吢 2024-09-01 13:22:04

如果您正在撰写研究报告,您应该使用 LaTeX。

我通常使用 LaTeX vancyvrb 包和 Verbatim

但是,另一种选择是使用 listings 包。它可以使用lstinputlisting命令直接输入文件。它会自动对行进行编号并使用 _ 字符而不是空格字符,但这是可编程的。真的很不错。

If you are writing a research report, you should be using LaTeX.

I typically use the LaTeX vancyvrb package and the Verbatim.

However, another option is to use the listings package. It can input a file directly using the lstinputlisting command. It automatically numbers your lines and uses the _ character instead of the space character, but this is programmable. It's really quite nice.

山色无中 2024-09-01 13:22:04

JD 和 Ben 说的话。

您应该使用适当的、既定的语法突出显示。 vy32 提到的 Latex 的 listings 包有Javascript 和 PHP 的语法高亮样式,Pygments 程序也是如此,它输出到 Latex、HTML 等和 RTF。

What JD and Ben said.

You should use appropriate, established syntax highlighting. Latex's listings package, mentioned by vy32, has syntax highlighting styles for both Javascript and PHP, as does the Pygments program, which outputs to, among others, Latex, HTML, and RTF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文