Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ascii to print table for correct rendering in all formats #1

Merged
merged 1 commit into from
Mar 31, 2012

Conversation

ramnathv
Copy link
Contributor

Using the html format does not lead to correct rendering of tables. Pandoc recognizes multiple table formats, of which the rest format is already included in ascii. I have modified these lines so that they are correctly rendered in the pdf format.

@yihui
Copy link
Owner

yihui commented Mar 19, 2012

Thanks! It is painful that we have to lose one of GitHub and LaTeX. rest does not work with GitHub, and xtable does not work with LaTeX... sigh

we can probably just use the pandoc format, which does not look too messy in GitHub:

mpg cyl disp hp drat


21.00 6.00 160.00 110.00 3.90
21.00 6.00 160.00 110.00 3.90
22.80 4.00 108.00 93.00 3.85
21.40 6.00 258.00 110.00 3.08
18.70 8.00 360.00 175.00 3.15
18.10 6.00 225.00 105.00 2.76


this is rest

+-------+------+--------+--------+------+
| mpg | cyl | disp | hp | drat |
+=======+======+========+========+======+
| 21.00 | 6.00 | 160.00 | 110.00 | 3.90 |
+-------+------+--------+--------+------+
| 21.00 | 6.00 | 160.00 | 110.00 | 3.90 |
+-------+------+--------+--------+------+
| 22.80 | 4.00 | 108.00 | 93.00 | 3.85 |
+-------+------+--------+--------+------+
| 21.40 | 6.00 | 258.00 | 110.00 | 3.08 |
+-------+------+--------+--------+------+
| 18.70 | 8.00 | 360.00 | 175.00 | 3.15 |
+-------+------+--------+--------+------+
| 18.10 | 6.00 | 225.00 | 105.00 | 2.76 |
+-------+------+--------+--------+------+

@ramnathv
Copy link
Contributor Author

I just realized that it does not have to be that way. Actually xtable prints a table based on getOption('xtable.type'), which is 'latex' by default, but can also take the value html. So, the trick then is to add a line inside 'knit.sh, which conditionally sets options(xtable.type = 'html'), when the format sought is html or github.

One issue with using shell scripts is that it does not handle the dependencies smartly, as a result of which it ends up doing a lot of repetitive work. I would recommend a makefile approach. Using a makefile, one can separate building the *.md files from source and then using pandoc to convert them into the desired format.

The 'html' vs 'latex' issue means that you need to generate two sets of *.md files, one for 'latex'/'epub' formats and the other for 'github'/'html'. I have scrapped up a makefile that does this and will push it to my fork of the repository when time permits.

I have scrapped up a makefile for this repository, which I will push when time permits.

@yihui
Copy link
Owner

yihui commented Mar 20, 2012

absolutely, a makefile is better

@cboettig
Copy link

Haven't quite figured out how this should work. I can set xtable.type to html when i want github output just fine, but what's the strategy when I want pdf output? It seems like I need to first generate a markdown file for pandoc to chew on, which means I want html output for that too?

@yihui
Copy link
Owner

yihui commented Mar 28, 2012

You have to re-compile the whole document for different types of output. To save time, I set the cache.path to different directories for different output formats. You can see them in https://github.com/yihui/knitr-book/blob/master/knit

@cboettig
Copy link

Sorry I didn't explain my question well.

I'm using a custom version of your knit file, along with a makefile.

I'm curious about where and when to set the option
option(xtable.type="html")

You have the type hardwired in as type='html' in the book Introduction,
so I'm guessing you leave it as html always rather than switch to latex
when you want pdf? (Because markdown is computing the pdf instead of
latex?)

I'm getting incorrectly formatted tables out doing this at the moment, not
sure why.
You can see the error in the table format I get on page 8 of the pdf in
this directory. I'm using the knit script to knit from source, and then a
makefile for pandoc commands on that source.
https://github.com/ropensci/rfishbase/tree/master/inst/doc/rfishbase

On Wed, Mar 28, 2012 at 4:13 PM, Yihui Xie <
reply@reply.github.com

wrote:

You have to re-compile the whole document for different types of output.
To save time, I set the cache.path to different directories for different
output formats. You can see them in
https://github.com/yihui/knitr-book/blob/master/knit


Reply to this email directly or view it on GitHub:
#1 (comment)

Carl Boettiger
UC Davis
http://www.carlboettiger.info/

@ramnathv
Copy link
Contributor Author

You will need to compile your rfishbase_knit_.md into two different formats, one that is gfm compatible and the other that is pdf compatible. For the gfm compatible version, you will need to set options(xtable.type = 'html'), while for the pdf compatible version, you need to set options(xtable.type = 'latex').

It is easy to put all this in a makefile. I have already gotten this working, but am cleaning up my source code before posting it on github. The makefile will automatically take a list of *_knit_.md files in a directory, and produce multiple versions of the document in pdf, docx, epub, html and gfm.

@cboettig
Copy link

I don't see the use case for xtable.type="latex" when the knit source file
is in markdown. Knit will create output that remains in markdown format,
except for the output of that table which will be in latex format, at which
point, you have a file with a mix of latex and markdown that pandoc cannot
interpret. It seems like you need to always have xtable.type="html" if the
source file is markdown and not Rnw or latex. Did I miss something?

On Wed, Mar 28, 2012 at 4:38 PM, Ramnath Vaidyanathan <
reply@reply.github.com

wrote:

You will need to compile your rfishbase_knit_.md into two different
formats, one that is gfm compatible and the other that is pdf
compatible. For the gfm compatible version, you will need to set
options(xtable.type = 'html'), while for the pdf compatible version,
you need to set options(xtable.type = 'latex').

It is easy to put all this in a makefile. I have already gotten this
working, but am cleaning up my source code before posting it on github.
The makefile will automatically take a list of *_knit_.md files in a
directory, and produce multiple versions of the document in pdf, docx,
epub, html and gfm.


Reply to this email directly or view it on GitHub:
#1 (comment)

Carl Boettiger
UC Davis
http://www.carlboettiger.info/

@ramnathv
Copy link
Contributor Author

When asked to generate pdf using latex, pandoc will let through any latex commands directly to pdflatex. Try it and you will see that it fixes your pdf tables.

@yihui
Copy link
Owner

yihui commented Mar 29, 2012

I guess I see where is the confusion now. The fact is I have not set options(xtable.type) yet. The current version cannot be converted to PDF with the table. The option can be set in the script knit.

@cboettig
Copy link

Thanks ramnathv, I hadn't realized that pandoc was okay with latex in the markdown. I had tried it before, but it was failing with the tables that I had -- it seems pandoc can't handle the latex tables that have math in the columns, such as xtable produces for the summary of a linear model. See this example (knit-source).

@ramnathv
Copy link
Contributor Author

Carl, it is not the math that is confusing pandoc, but the pipe sign in Pr($>$$|$t$|$). If you run pandoc with the --parse-raw option, you will see the latex error it gives. If you change the | to \mid, you will find that it compiles to pdf without any problems.

@ramnathv ramnathv closed this Mar 31, 2012
@cboettig
Copy link

Unfortunately that means manually correcting the output of summary/xtable,
doesn't it?
On Mar 30, 2012 6:44 PM, "Ramnath Vaidyanathan" <
reply@reply.github.com>
wrote:

Carl, it is not the math that is confusing pandoc, but the pipe sign
in Pr($>$$|$t$|$). If you run pandoc with the --parse-raw option, you
will see the latex error it gives. If you change the | to \mid, you
will find that it compiles to pdf without any problems.


Reply to this email directly or view it on GitHub:
#1 (comment)

@yihui yihui reopened this Mar 31, 2012
yihui added a commit that referenced this pull request Mar 31, 2012
Use ascii to print table for correct rendering in all formats
@yihui yihui merged commit 5b39de8 into yihui:master Mar 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants