Re: Latex listings package?

52 views
Skip to first unread message

Bob Carpenter

unread,
Apr 3, 2015, 8:00:09 PM4/3/15
to stan...@googlegroups.com
[moved to stan-dev]

> On Apr 4, 2015, at 4:46 AM, Daniel Lee <bea...@alum.mit.edu> wrote:
>
> have you seen this?
> http://en.m.wikibooks.org/wiki/LaTeX/Source_Code_Listings
>
> It looks like it's what we would want to include compilable examples in the manual.

I've seen various versions of this kind of thing.

If we wanted to use "listings" with Stan code, we'd need to
write a style to render it.

And what we really want is something that also pulls
out fragments of code files, unless we want to move to some
kind of all-or-nothing policy. It's much more verbose, but
can be less confusing.

They also mention the package minted. It uses Pygments
and I believe Jeffrey Arnold already wrote a Pygments style
for Stan.

- Bob

Jeffrey Arnold

unread,
Apr 4, 2015, 12:39:12 AM4/4/15
to stan...@googlegroups.com
It'll be pretty easy to do. That's why I defined the stancode environment in https://github.com/stan-dev/stan/commit/2a5ba0bfa7f14f89af704ab0a7718a05b2846953. You can just redefine it to listings or a minted environment. 

For minted, this branch has an implementation https://github.com/stan-dev/stan/tree/feature/issue-1132-pygmentize. It takes a while to compile the manual. But we could define two make targets: a manual with and without listings.

I also wrote a listings package for Stan and BUGS  a while back:  https://github.com/jrnold/lstBUGS




- Bob

--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Lee

unread,
Apr 4, 2015, 11:46:10 AM4/4/15
to stan...@googlegroups.com
On Sat, Apr 4, 2015 at 12:39 AM, Jeffrey Arnold <jeffrey...@gmail.com> wrote:
It'll be pretty easy to do. That's why I defined the stancode environment in https://github.com/stan-dev/stan/commit/2a5ba0bfa7f14f89af704ab0a7718a05b2846953. You can just redefine it to listings or a minted environment. 

Nice! I didn't notice the stancode environment.

 
For minted, this branch has an implementation https://github.com/stan-dev/stan/tree/feature/issue-1132-pygmentize. It takes a while to compile the manual. But we could define two make targets: a manual with and without listings.

Does using listings take a long time to compile? I was hoping to just use it to bring in external files with a start line and an end line.



 
I also wrote a listings package for Stan and BUGS  a while back:  https://github.com/jrnold/lstBUGS



On Fri, Apr 3, 2015 at 4:59 PM, Bob Carpenter <ca...@alias-i.com> wrote:
[moved to stan-dev]

> On Apr 4, 2015, at 4:46 AM, Daniel Lee <bea...@alum.mit.edu> wrote:
>
> have you seen this?
> http://en.m.wikibooks.org/wiki/LaTeX/Source_Code_Listings
>
> It looks like it's what we would want to include compilable examples in the manual.

I've seen various versions of this kind of thing.

If we wanted to use "listings" with Stan code, we'd need to
write a style to render it.

And what we really want is something that also pulls
out fragments of code files, unless we want to move to some
kind of all-or-nothing policy.  It's much more verbose, but
can be less confusing.

Yes, listings can do this based on line numbers. Yeah, I know, not the most robust thing ever, but it'll work for us for the time being, right? I don't think we change the examples that often.
 

They also mention the package minted.  It uses Pygments
and I believe Jeffrey Arnold already wrote a Pygments style
for Stan.

As Jeff mentioned, using Pygments takes time. I would like to pull out the things that should compile into separate files, then include them. Then we can test that the bits of code are actually compilable using the Stan compiler.

Daniel

Jeffrey Arnold

unread,
Apr 4, 2015, 1:24:13 PM4/4/15
to stan...@googlegroups.com
I pushed some updates to issue-1132-pygmentize. It creates two manuals - with and without highlighting. Now stan-manuals.sty takes an option highlight which will determine whether any code in stancode or stancodefile environments is highlighted.

You can use the listings package; I don't think the highlighting looks particularly good as it can only do keywords and comments. However, now minted is much faster. In the months since I last looked at it there's been a lot of work on it. Now it caches the code chunks and works much faster.

Also putting code in external files is a separate problem from highlighting it. You could keep using the fancyvrb package and use VerbatimInput.


Daniel Lee

unread,
Apr 6, 2015, 12:23:51 AM4/6/15
to stan...@googlegroups.com
Hi Jeff,

Thanks for getting this going.

On Sat, Apr 4, 2015 at 1:24 PM, Jeffrey Arnold <jeffrey...@gmail.com> wrote:
I pushed some updates to issue-1132-pygmentize. It creates two manuals - with and without highlighting. Now stan-manuals.sty takes an option highlight which will determine whether any code in stancode or stancodefile environments is highlighted.

It looks good. But, I can't get the references to generate properly. When I build the manual, I get a bunch of "(?)"s is both the highlighted and non-highlighted versions.
 

You can use the listings package; I don't think the highlighting looks particularly good as it can only do keywords and comments. However, now minted is much faster. In the months since I last looked at it there's been a lot of work on it. Now it caches the code chunks and works much faster.


That's great. I was looking at the listings package just to include files.
 

Also putting code in external files is a separate problem from highlighting it. You could keep using the fancyvrb package and use VerbatimInput.



At this point, I'd be happy with being able to include files. The additional requirement is to be able to take segments of files. That's why I thought the listings package was appropriate.

It looks like the fancyvrb package will also handle this ok.

Jeffrey Arnold

unread,
Apr 11, 2015, 12:11:28 AM4/11/15
to stan...@googlegroups.com
The references should be working now. I forgotten to uncomment some includes for tex files from earlier debugging.
Reply all
Reply to author
Forward
0 new messages