ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <schuster.wolfgang@googlemail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Syntax highlighting for C-code
Date: Sun, 15 Jan 2012 12:06:03 +0100	[thread overview]
Message-ID: <0BBB1DD6-ED73-49B4-990C-EF7810EF378F@googlemail.com> (raw)
In-Reply-To: <4F100ED0.4000608@weickelt.de>


Am 13.01.2012 um 12:00 schrieb Richard Weickelt:

> Hi,
> 
> I've tried to include some C-code into my document, but failed to enable syntax highlighting.
> 
> Tested on: linux-64, context-2011.05.18 (same with the beta) stand-alone mkIV
> 
> 1) \starttyping[option=C] just prints verbatim text. There seems to be no formatter for C out of the box.

There is no formatter for C code in MkIV but when you write one send the file to Hans and he can include it in the distribution.

> 2) t-vim did not work. It failed somewhere (unknown command sequence \installspacehandler) on loading (\usemodule[vim])
> 
> 3) http://wiki.contextgarden.net/Verbatim_text
> I tried to download pret-c and put it into the modules folder, but writing \installprettytype[C][C] failed, because it's not known (in mkIV).

MkII and MkIV have different implementation to format source code.

> 4) mkII does not complain to exec \installprettytype[C][C], but this does not change anything either. \starttyping[option=C] seems to call a (maybe builtin?) formatter, but I could not get colors to work.


The following is MkII only. There are two ways to have formatted C code, the first is to define a C environment with \definetype[C][option=C] and then you can put the code between \startC and \stopC, the second is to use the normal typing environment and pass “option=C” as argument. To get colors in your code you have to enable them first with \setupcolors[state=start].

% engine=pdftex

\setupcolors[state=start]

\definetyping[C][option=C]

\starttext

\startC
#include<stdio.h>
 
int main()
{
   printf("Hello World\n");
   return 0;
}
\stopC

\blank[2*line]

\starttyping[option=C]
#include<stdio.h>
 
int main()
{
   printf("Hello World\n");
   return 0;
}
\stoptyping

\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


      parent reply	other threads:[~2012-01-15 11:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-13 11:00 Richard Weickelt
2012-01-14 15:40 ` [***SPAM***] " Peter Münster
2012-01-14 18:03   ` Aditya Mahajan
2012-01-15 11:06 ` Wolfgang Schuster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0BBB1DD6-ED73-49B4-990C-EF7810EF378F@googlemail.com \
    --to=schuster.wolfgang@googlemail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).