Thursday, November 6, 2008

Conditional Formatting

Because I want to write for multiple output devices, some of which support color and some of which do not, I'd like to be able to specify conditional formatting as I write. In a recent article, for example, I use blue as my standard code color with red as a highlight color:
  void g(MakeFeatures<tepsafe>::type features)
{
int xVal, yVal;
...
f(xVal, yVal, features);
...
}

If I were writing for a device with no color support, I'd probably use black as my standard code color and something like bold as a highlighting technique:
  void g(MakeFeatures<tepsafe>::type features)
{
int xVal, yVal;
...
f(xVal, yVal, features);
...
}
I don't know whether traditional WYSIWYG word processors support this kind of thing. As far as I know, FrameMaker doesn't, but perhaps there is a way to coax it into exhibiting this behavior.

More problematic, I think, is conditional formatting in figures and diagrams. Here's a figure from the same article:

If I wanted to express the same highlighting information in a black and white presentation, I could "bold-face" the lines:

The problem is, I don't know of any software that will let me specify named line styles and define them differently for different contexts. In the figure above (there's only one figure, it's just expressed in two different ways), I want to define and apply a "highlight graphic" line style for some arrows and rectangles, using different definitions of this style.

I can think of a couple of workarounds. I could create different versions of the diagram and use conditional content constructs to choose the one I want. The problem with that approach is that it violates my single-source constraint: I don't want to maintain multiple copies of the same figure with different formatting any more than I want to maintain multiple copies of the same text with different formatting.

Another workaround would be to have a single diagram that uses, say, lines that are both colored and dashed, so they'd be distinguishable on both color and non-color output devices. (On non-color devices, they'd simply look dashed.) For text, I could use both coloring and underlining. (On non-color devices, such text would simply be underlined.) This approach has the advantage that it works, but it really strikes me as kind of a hack.

How do you suggest I handle the problem of conditional formatting?

3 comments:

David Abrahams said...

Hi Scott,

The traditional word processor feature you're looking for is called "styles." See MS-Word, OpenOffice, ...

As for the software to let you alter the presentation of your diagrams, I'm afraid that's called "PostScript." http://www.w3.org/Graphics/SVG/About might also have some of what you need. But ultimately, this project is going to require some programming, IMO. I don't think you'll be able to cobble together off-the-shelf tools with GUI interfaces that do just what you want.

George Reilly said...

SVG is supposed to support CSS, and CSS supports different stylesheets for different media (screen, print, &c). I've never tried this; I have no idea if it's workable in practice.

Look at Inkscape if you do start experimenting with SVG.

Jim said...

You could try Photoshop, copy the layer and play with the curves etc.