I should have explained better. PGML markup will translate that thing (n octothorpes at the start of a line) into an hn header tag in HTML.
And it does something reasonable to make a "header" for LaTeX output too.
Of the options that have been presented, this is what I'd recommend. It's a tool that is already built, and it doesn't make you write output-specific code into the PG file.