mkoohafkan / kfigr

A streamlined cross-referencing package designed specifically for use with knitr.
GNU General Public License v3.0
25 stars 10 forks source link

Putting 'Figure X: Description' into the figure caption automatically #1

Closed bryanhanson closed 10 years ago

bryanhanson commented 10 years ago

Thanks for making this package. It is quite nice. I notice that if I don't specify a caption, I get a default caption related to the chunk name. What I would like to do is capture the text part generated by r figr('chunk-name', type = 'figure') which would be, for instance, "Figure 1" and use it as part of the figure caption. For example, if I said fig.cap = "descriptive caption" it would be really nice if kfigr turned the figure caption into "Figure 1: descriptive caption". I hope this is clear. Yuhui has something similar, but it would operate independently and the numbering may get out of register.

mkoohafkan commented 10 years ago

Hmm, kfigr doesn't actually define any figure captioning (whereas the original figr package did). I don't get default figure captions so I'm not sure why that happens, but you can produce a figure label with

paste(figr('test-chunk', TRUE), 'a caption', sep = ': ')

which is basically the last line of the fn() function in Yihui's example. kfigr knows not to increment the same figure more than once so there shouldn't be any numbering problems (but it's worth testing). If you use opts_knit$set(eval.after='fig.cap') you can define the caption in a variable within the given code chunk. Does that do what you need?

bryanhanson commented 10 years ago

Thanks Mike. In the meantime I used Yihui’s approach with kfigr and they seem to co-exist fine as long as you process to html. When going to pdf you get some duplication like Figure 2: Figure 1: caption. So I have a working option (and we’re really at the cusp of switching to full LaTeX anyway, the simplicity of markdown is getting pretty hammered tracking figures). By the way, if I put nothing at all in the chunk instructions about fig.cap’s I get “Plot of chunk XYZ” as the caption. Thanks again, Bryan

On Jul 25, 2014, at 3:06 PM, mikeck notifications@github.com wrote:

Hmm, kfigr doesn't actually define any figure captioning (whereas the original figr package did). I don't get default figure captions so I'm not sure why that happens, but you can produce a figure label with

paste(figr('test-chunk', TRUE), 'a caption', sep = ': ') which is basically the last line of the fn() function in Yihui's example. kfigr knows not to increment the same figure more than once so there shouldn't be any numbering problems (but it's worth testing). If you use opts_knit$set(eval.after='fig.cap') you can define the caption in a variable within the given code chunk. Does that do what you need?

— Reply to this email directly or view it on GitHub.

mkoohafkan commented 10 years ago

I see, yes I designed kfigr specifically for HTML output and I haven't really tested it with pdf output. For that reason (and others) I'll probably never try to push this package to CRAN. Still, I'm using knitr v 1.6 and there is no fig.cap hook defined, so I'm not sure why you're getting a default figure caption. kfigr doesn't define a fig.cap hook in zzz.r so perhaps this is something knitr does with pdfs?

bryanhanson commented 10 years ago

Who knows. Go ahead and close this issue as I have what I need. Thanks, Bryan

On Jul 27, 2014, at 6:00 PM, mikeck notifications@github.com wrote:

I see, yes I designed kfigr specifically for HTML output and I haven't really tested it with pdf output. For that reason (and others) I'll probably never try to push this package to CRAN. Still, I'm using knitr v 1.6 and there is no fig.cap hook defined, so I'm not sure why you're getting a default figure caption. kfigr doesn't define a fig.cap hook in zzz.r so perhaps this is something knitr does with pdfs?

— Reply to this email directly or view it on GitHub.