Can I borrow your highlighter please?

Are you one of those people who always have a highligher ready when reading a book. Miss that functionality in TeX? Don’t worry, its easy to highlight text in ConTeXt


And then

\highlight{word or sentences}

highlights text. This is based on the new mechanism in MkIV that is used to define underbars, overbars, and overstrike. Tweaking it a little bit gives us a highlighter, which afterall is just a fancy line (Aside: in TeX parlance, a line is called a rule. The ConTeXt mechanism that I am using is called a bar. I’ll just call them lines, ’cause that’s what they are.)

The option order tells whether the line should go in the foreground or the background. Obviously, I choose background. rulethickness is, well, the thickness or the rule (err. I mean line). The default units are ex and I choose the thickness to be 2.5ex (I don’t know why the units and the numerical value of thickness are specified separately). By default, the line is centered at the bottom of the line. The offset=1.25 moves it 1.25ex up, so that the line appears centered. continue=yes tells that the line should be drawn continuously. The default is continue=no which breaks the line after each work. The option color simply specifies the color.

Why do I care about such highlighting? It may be useful for presentations and such, but my interest is for a proper mechanism for universal source highlighting. The idea is that I should be able to define a source highlighting style and use any syntax highlighting program: vim, pgyments, source-highlight, HsColor, and so on. Each of these programs just mark the syntax region and leave the highlighting of the region to TeX. For a universal syntax highlighter, I can define the syntax highligting rules and just map them to output of the different programs.

Source highlighting normally involves changing font style (bold, italic, etc), changing font color, underlining, overstriking, changing backgorund color, and so on. At first I thought that I will use \framed for that: it supports all these features by default. However, \framed does not split across lines. The next choice was \textbackground which is extremely versatile: it supports all the features of \framed, and, at the same time, splits across lines and pages. But, \textbackground seemed to be an overkill. I think that \underbar mechanism is just right. It can take care of underline, overstrike, background colors; while the usual \dostartattributes is sufficient to take care of font style and color. More on this later…


4 thoughts on “Can I borrow your highlighter please?

  1. I would need some different functionality, like the old MkII ‘underbar’ where you could set a different linestyle (for example: dots, or small line segments, and all sorts of combinations). Further I noticed that the ‘underbar’ moves up or down when using super or subscripts. I don’t want that. Can this be done in Context Mk iv, or does one need metapost functionality?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s