not a beautiful or unique snowflake (nothings) wrote,
not a beautiful or unique snowflake
nothings

lazyweb

Look at me learning LaTeX. Lordy, it totally sucks to have to express everything in ASCII, so there's no way to express things out of band--which just works in a GUI program (like, say, Word). Mind you, I'm no Microsoft fan; I mean, I'm trying LaTeX for a reason, here.

Here's what I want to do. I want to put a fragmentary C program listing inline in a box (a la an fbox minipage or some such). And I want to hilight some of the lines somehow, for example by setting their background in a different color (or maybe by putting a big arrow symbol in front of those lines). And I want to, you know, make it convenient to use.

So I poked around in a FAQ and installed fancyvrb, a nice verbatim package that allows markup inside the verbatim blocks. (I also installed fancybox to maybe use that instead of fancyvrb's framing, but haven't tried it yet.)

I have the following problems:

  • I can't figure out how to make fancyvrb's "commandchars" work properly. There are a number of free characters in C++: $, @, `, \ -- but I can only make it work if I use \ { }, or if I use non-active characters. That kind of defeats the whole point.
  • I can't figure out how to set the background color for a line. If I do \colorbox{grey}{...} around my text, that works, except the spacing is all screwed up--remember, I'm trying to do this in a verbatim environment, so I need (a) to preserve spacing, and (b) to see how things line up. So, I've set up a fancyvrb Verbatim environment with \ { } as the commandchar, and I do this:
    \begin{code}
          foobar1();
    \colorbox{grey}{
          foobar2();}
          foobar3();
    \end{code}
    

    This doesn't work: foobar2() ends up indented by an extra space, and the grey background doesn't extend all the way across the frame--it stops at the last character of foobar2(). If I enable a commentchar and add it to the end of the \colorbox line, it doesn't help.


Anybody know how to do this? If you don't know fancyvrb, that's ok, just tell me the easy and convenient way to code this. 'Cause otherwise, it seems like the simplest solution is to WRITE A FUCKING PREPROCESSOR. I guess the other way to approach this is to remove the nesting: put each of the highlighted-and-non-hilighted sections in their own verbatim'd groups, and then wrap that whole thing in a box. But that's going to get crazy wordy. The fact that colorbox isn't an environment means you can't just wrap its begin and end inside a pair of macros. If it's going to be that ugly I'd just rather write the preprocessor.

I'm sure LaTeX is capable of doing something like this if you have sufficient LaTeX mojo; it's the fact that it can't be expressed straightforwardly that makes me worry. Of course, as I said, since I'm working on a verbatim environment with markup, naturally that's a pretty freaking tricky area, and maybe TeX is better for math than for describing programming, but the fact that stuff like commandchars doesn't actually work as advertised (well, to be honest, the documentation says very little--and even less about defineactive, with which I have similar problems, unfortunate since I was hoping to use to make it more concise) doesn't make me very happy about finally investing the time to learn it.
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 10 comments