yonicd/texPreview

A few suggestions

haozhu233 opened this issue · 7 comments

Hi, @yonicd,

Thanks again for this awesome package! Here are a few suggestions that I came up with when I was using this package. They are just my personal opinions in my special use cases. :)

  1. The stem option: When I was trying to use texPreview for the first time, I didn't expect I need to provide a stem option to get it work. It makes sense to provide that when users want to save. However, if users only want to preview quickly, I guess you can just give it a random name internally or just use the time.

  2. margin_right: When I was trying to save a table to image, I did spent a while wondering why there is a large white space on the right side, before I found out the default setting for margin is margin=list(left=10, top=5, right=50, bottom=5). I guess it helps improve the looks in the viewer but not so much when my only purpose is to save the image.

  3. latex packages: It is a little difficult to understand how to use buildUsepackage to load extra latex packages to the tex file. Also, I feel like it should be users' responsibility to make sure the packages they asked to include is in their computer. ;)

  4. I do hope there could be an option to change the default density because it's a little too low for me.

I hope you find these suggestions being useful. :)

thank you for the comments.

  1. you are right, that can be defaulted (it has to have a name for the book keeping behind the scenes).

  2. I never had that problem with extra padding in my testing (we use it to save most of the time), if you can give an example that would be great.

  3. mapply is a bit heavy to use, i'll give that another stab (i wanted to keep the input as base r)

  4. i can open up density as a param.

  1. For example,
aaa <- knitr::kable(mtcars[1:8], "latex")
texPreview::texPreview(aaa, "test", fileDir = ".", imgFormat = "jpg")

gives me the following pic. I'm using jpg for the white background. As you can see, the right margin is too wide with the default setting.
screen shot 2017-08-28 at 2 58 52 pm

got it, dont know why it was set to 50. 10 should be more than enough (anyways it has svgpanzoom now in viewer by default so the padding doesnt matter)

btw why didnt you opt to have texPreview as a depends in kable in the end? (not a pressure to do it, just wondering for future pkg making to make them easier to have ppl dep on them).

it would be

pkgs <- c('preview',
             'xcolor',
             'varwidth',
             'amssymb',
             'ifxetex',
             'ifluatex',
             'fixltx2e',
             'polyglossia',
             'booktabs',
             'longtable',
             'array',
             'wrapfig',
             'colortbl',
             'mathspec',
             'xltxtra',
             'xunicode'
             )

opts <- rep(list(NULL), length(pkgs))
opts[[1]] <- c('active','tightpage')
opts[[2]] <- c('table')

texPkgs <- unlist(mapply(texPreview::buildUsepackage,
              pkg =        pkgs,
              options=     opts
              ))

texPreview(enc2utf8(as.character(kable_input)),
stem=paste0("table_", format(Sys.time(), "%Y-%m-%d_%H:%M:%S")),
engine='xelatex',
usrPackages=texPkgs)

Also, when the fileDir is specified, it would be nice to do some auto clean ups for those latex log files. You may also set an option there and leave the decision to the users.

sure, that can be added as an option.

Closing this issue as we are collaborating.