Keywords and other inline expressions can be highlighted and rendered in fixed font by surrounding them with "=" signs. For example, the notorious function name,
receive {P, NP} -> ok end, was just embedded there using the following syntax:
=receive {P, NP} -> ok end=
Small source code snippets can be formatted using the
SyntaxHighlightingPlugin syntax, for example:
%begin erlang%
consumer(0, NC, _, Main) -> Main ! {self(), NC};
consumer(N, NC, P, Main) ->
P ! {self(), next}, %% signal buffer empty
receive %% receive buffer full
{data, Value} -> consumer(N-1, NC+1, P, Main) %% empty buffer
end.
%end%
This results in the code being displayed as follows:
consumer(0, NC, _, Main) -> Main ! {self(), NC};
consumer(N, NC, P, Main) ->
P ! {self(), next}, %% signal buffer empty
receive %% receive buffer full
{data, Value} -> consumer(N-1, NC+1, P, Main) %% empty buffer
end. |
For any non-trivial code, and perhaps even for some trivial code, it's better to keep the code separately from the book text. Among other things, this will allow the code to be more easily run and tested within Erlang, as well as making it easier to package the code for distribution.
The current approach to including external code is that for each code sample, a topic should be created in the Erl web, for example Erl.Start1. Note that using a
WikiName may be helpful, but it's not essential in this case. The raw source code should be stored in this topic - for now, simply cutting and pasting the source from a local copy should suffice, later we'll set up ways to manage this better.
Once the code is stored in a topic, it can be included in the book using syntax like this:
%begin erlang%
%INCLUDE{"Erl.Start1"}%
%end%
This results in the following:
--
AntonVanStraaten - 31 Mar 2004
--
BrentAFulgham - 19 Aug 2004