Skip to content

Commit

Permalink
完善安装说明
Browse files Browse the repository at this point in the history
  • Loading branch information
bubifengyun committed Sep 28, 2018
1 parent 5004b9a commit 8a7d64b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 92 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
pdf:
Rscript _render.R "bookdown::pdf_book"

gitbook:
Rscript _render.R "bookdown::gitbook"

all:
Rscript _render.R

wordcount:
@texcount _book/sjtu-thesis-rmd.tex -inc -ch-only | awk '/total/ {getline; print "纯中文字数\t\t\t:",$$4}'
@texcount _book/sjtu-thesis-rmd.tex -inc -chinese | awk '/total/ {getline; print "总字数(英文单词 + 中文字)\t:",$$4}'
54 changes: 1 addition & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,7 @@

请先阅读[上海交通大学学位论文Latex模板](https://github.com/sjtug/SJTUThesis)的软件要求,这也是本模板的要求,然后安装 Pandoc,R 和 make 即可,如果可以安装 RStudio 更好。

### 一、Linux 下使用
下面以深度操作系统15.5版本下的运行为例说明。

#### 安装 R 语言和 RStudio 编译器

当前深度Linux 操作系统的 R 语言的版本,还是能够编译的。请确保当前 `rstudio` 的版本高于 1.0.0。

```bash
$ sudo apt-get install r-base r-base-dev
$ sudo apt-get install rstudio
```

如果不能满足,请参考[R官网](https://cran.r-project.org/bin/linux/debian/#debian-sid-unstable)[RStudio官网](https://www.rstudio.com/products/rstudio/download/)


#### 安装 texlive 软件

请确保 texlive 为2015年及之后的版本。

```bash
$ sudo apt-get install texlive-full
```
如果版本太低,推荐[texlive官网](http://tug.org/texlive/)下载最新的 texlive 安装,且需要创建系统链接,以便在 bash 内可用 xelatex 等。

#### 安装 pandoc 软件

```bash
$ sudo apt-get install pandoc
```

pandoc 的版本应高于 2.0.0,版本不够请自行解决。

#### 运行编译成书

1、下载解压缩,运行

```bash
make
```

如果报错,请自行解决或联系我。

2、如果您已经安装 RStudio 软件,打开 RStudio 软件,在弹出的界面,左上角点击 File->Open Project,选中 *./SJTUThesis-Rmd.Rproj* 文件打开,点击右上角靠下的一栏,有个 `Build` 格,会出现 `Build Book` 等按钮。点击 `Build Book` 就会生成 PDF 书籍了,位于 *./_book/* 文件夹下。

可能需要安装一些R包,请根据问题下载。

### 二、Windows 下使用


### 三、苹果系统下使用

详情参阅[这里](./rmd/101-intro.Rmd)

## 反馈问题

Expand Down
44 changes: 14 additions & 30 deletions _render.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
quiet = "--quiet" %in% commandArgs(FALSE)
formats = commandArgs(TRUE)
format = commandArgs(TRUE)
travis = !is.na(Sys.getenv('CI', NA))

# install bookdown
local({
r = getOption('repos')
if (!length(r) || all(r['CRAN'] == '@CRAN@')) r['CRAN'] = 'https://cran.rstudio.com'
options(repos = r)
})
if (system.file(package = 'bookdown') == '') install.packages('bookdown')

src = (function() {
attr(body(sys.function()), 'srcfile')
})()$filename
if (is.null(src) || src == '') src = '.'
owd = setwd(dirname(src))

# provide default formats if necessary
if (length(formats) == 0) formats = c(
'bookdown::pdf_book', 'bookdown::epub_book', 'bookdown::gitbook'
)
# provide default format if necessary
if (length(format) == 0) format = 'bookdown::pdf_book'
# render the book to all formats unless they are specified via command-line args
for (fmt in formats) {
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = %s)", fmt, quiet)
res = bookdown:::Rscript(c('-e', shQuote(cmd)))
if (res != 0) stop('Failed to compile the book to ', fmt)
if (!travis && fmt == 'bookdown::epub_book')
bookdown::calibre('_book/bookdown.epub', 'mobi')
}

r = '<body onload="window.location = \'https://bookdown.org/yihui\'+location.pathname">'
for (f in list.files('_book', '[.]html$', full.names = TRUE)) {
x = readLines(f)
if (length(i <- grep('^\\s*<body>\\s*$', x)) == 0) next
# patch HTML files in gh-pages if built on Travis, to redirect to bookdown.org
if (travis) x[i[1]] = r
i = grep('<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">.+</a>', x)[1]
# shorter title on the toolbar
if (!is.na(i)) x[i] = gsub('bookdown: ', '', x[i], fixed = TRUE)
i = c(
grep('^\\s*<meta name="generator" content="bookdown [.0-9]+ and GitBook [.0-9]+">$', x),
grep('^<meta name="date" content="[-0-9]+">$', x)
)
if (travis && length(i)) x = x[-i]
writeLines(x, f)
}

if (length(formats) > 1) bookdown::publish_book()
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = %s)", format, quiet)
res = bookdown:::Rscript(c('-e', shQuote(cmd)))
if (res != 0) stop('Failed to compile the book to ', format)

setwd(owd)
10 changes: 8 additions & 2 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
# 为了让日期显示为英文
locale = Sys.setlocale(category = "LC_TIME", locale = 'en_US.UTF-8')
localSystem = R.Version()$system
options(
htmltools.dir.version = FALSE, formatR.indent = 2, width = 55, digits = 4
)
# 填上你需要用到的包
if (!length(getOption('repos'))) options(repos = c(CRAN = 'https://cran.rstudio.com'))
lapply(c('DT', 'citr', 'formatR', 'svglite', 'webshot'), function(pkg) {
lapply(c('DT', 'citr', 'formatR', 'svglite', 'webshot', 'devtools'), function(pkg) {
if (system.file(package = pkg) == '') install.packages(pkg)
})
if (!grepl('windows', localSystem) && system('hash phantomjs 2>/dev/null') != 0)
webshot::install_phantomjs()
if (system.file(package = 'tinytex') == '' || packageVersion("tinytex") < '0.6.4')
devtools::install_github('yihui/tinytex')
# 生成依赖包
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown', 'htmlwidgets', 'webshot', 'DT',
Expand Down
14 changes: 13 additions & 1 deletion rmd/101-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ $\$$ sudo apt-get install r-base r-base-dev \
rstudio texlive-full pandoc make
```

如果不能满足,请参考相关软件官网,下载最新版本。
如果不能满足,请参考相关软件官网,下载最新版本。我的[博客](https://my.oschina.net/bubifengyun/blog/1936119)记录了如何安装最新版 texlive,有需要的可以去看看。[pandoc官网](https://github.com/jgm/pandoc/blob/master/INSTALL.md)有其安装教程。R 语言的安装方法[官网镜像](https://mirrors.tuna.tsinghua.edu.cn/CRAN/)也可找到,这里就不赘述了,有问题可以邮件联系。

曾经在 Lubuntu 下试着安装过。一般先安装 `make`,运行命令,仍旧出错,提示没有`RScript`,接着安装`r-base r-base-dev`。再接着,`sudo make`还是出错。最后是`pandoc`版本问题了。由于 Lubuntu 版本太老,没能更新好。总结一下,

```{.bash numbers=none}
$\$$ sudo apt-get install make r-base r-base-dev -y
$\$$ sudo make
```
第一次编译,可能需要安装很多软件,请静静等待。后面,直接运行下面这条语句,实现编译。

```{.bash numbers=none}
$\$$ make
```

### Windows 下使用

Expand Down

0 comments on commit 8a7d64b

Please sign in to comment.