There’s a useful tradition of using a typewriter font, or more generally some monospaced font, for bits of code sprinkled in prose. The practice is analogous to using italic to mark, for example, a French mot dropped into an English paragraph. In HTML, the code
tag marks content as software code, which a browser typically will render in a typewriter font.
Here’s a sentence from a new article on Python at Netflix that could benefit a few code
tags.
These features (and more) have led to increasingly pervasive use of Python in everything from small tools using boto to talk to AWS, to storing information with python-memcached and pycassa, managing processes with Envoy, polling restful APIs to large applications with requests, providing web interfaces with CherryPy and Bottle, and crunching data with scipy.
Here’s the same sentence with some code
tags.
These features (and more) have led to increasingly pervasive use of Python in everything from small tools using
boto
to talk to AWS, to storing information withpython-memcached
andpycassa
, managing processes withEnvoy
, polling restful APIs to large applications withrequests
, providing web interfaces withCherryPy
andBottle
, and crunching data withscipy
.
It’s especially helpful to let the reader know that packages like requests
are indeed packages. It helps to clarify, for example, whether Wes McKinney has been stress testing pandas or pandas
. That way we know whether to inform animal protection authorities or to download a new version of a library.
And in LaTeX,
{tt pandas}
.That is a very old and not generally approved of way to do things in LaTeX Matt.
A far supriour way is to use the Listings package: http://stackoverflow.com/questions/586572/make-code-in-latex-look-nice has some very good examples, and Wikibooks has more: http://en.wikibooks.org/wiki/LaTeX/Packages/Listings
And if you’re using a monospaced font, make sure you use the family. I’ve seen many websites built on Mac that use Monaco as their monospaced font but fail to specify the fallback. This renders whole code blocks in a default font.
A simple
font-family: Monaco,monospace
would solve the issue. I’m not talking about news websites but about programmer focused sites like Socket.io and slim-lang.com (These sites had only Monaco until recently).Interesting, I just started looking at Python, might try to learn it.
Agree about code listings in general. But it’s not clear that program names, when used outside of a code context, or outside the context of showing how to run the program, should be monospaced. Do we monospace LaTeX, e.g.? Or Microsoft Word? etc.
Yawar: I agree that’s fuzzy. I would set libraries in monospace but not programs. I think that’s conventional. And it makes sense: program names are generally capitalized and more familiar.
I’d set command line utility names like
sed
in monospace because they are not capitalized and because they’re conceptually more like libraries for the shell than like programs. Also, some of them are common words liketop
andnice
.Martin and Dmitry: Good points.
Allowing zeros does make things more difficult, maybe impossible. Certainly impossible to brute force by computer. Maybe there are theoretical ways to limit, for example, the number of primes of the form 1000….0003, but that’s a much harder question.
I find the O’Reilly Style guide works well for text with code in it. More info at http://oreilly.com/oreilly/author/stylesheet.html