<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>TinyTeX on Den | 登</title>
    <link>/t/</link>
    <description>Recent content in TinyTeX on Den | 登</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-US</language>
    <lastBuildDate>Sat, 02 Dec 2017 00:00:00 +0000</lastBuildDate>
    <atom:link href="/t/" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Why TinyTeX?</title>
      <link>/t/pain/</link>
      <pubDate>Fri, 15 Dec 2017 00:00:00 +0000</pubDate>
      
      <guid>/t/pain/</guid>
      <description>
        <![CDATA[
        <p>Some developers may doubt if I&rsquo;m just reinventing wheels. I certainly don&rsquo;t want to reinvent wheels for no reason. As I said on the homepage, my own pain with existing LaTeX distributions is that they are often too big, and the documentation, while being comprehensive and useful, usually does not highlight the most useful part to me (how to find and install a missing package).</p>

<p>I also dislike the fact that it often requires <code>sudo</code> (on *nix) to manage LaTeX packages. For personal computers, I don&rsquo;t see any point of requiring <code>sudo</code>, considering the fact that TeX Live can be a self-contained folder that can be placed anywhere on your computer. I waited for a couple of years before <code>tlmgr</code> was finally available on Debian/Ubuntu, and I was <a href="https://tw.com/xieyihui/status/397238590523973632">extremely excited</a> about it, but soon disappointed, because it seemed to be broken and not usable at all (couldn&rsquo;t do anything with it). I checked it again this year, and it still seems to be broken. Perhaps I didn&rsquo;t use it correctly (anything I try will lead to errors), but you are only allowed to use the user mode of <code>tlmgr</code>, which is very restrictive to me.</p>

<p>My daily OS is macOS, and the officially recommended TeX Live distribution is MacTeX, which contains several additional packages that I don&rsquo;t need, such as the TeX Live Utility (I know how to use the <code>tlmgr</code> command), TeXShop (I use R Markdown primarily and hope not to edit or even read raw LaTeX if possible), LaTeXiT, and so on.</p>

<p>In fact, I appreciate one nice feature of MiKTeX on Windows (which seems to be cross-platform now): automatically installing missing LaTeX packages. I think this is very helpful, so I borrowed this feature to the R package <strong>tinytex</strong>, and R users can enjoy the same feature when using TeX Live or TinyTeX. That said, even the basic MiKTeX is still too big, and one issue that drives me crazy is <code>bibtex.exe</code> in MiKTeX: it always adds the <code>.bib</code> extension to the bibliography database file in the <code>.aux</code> file, e.g., when we have <code>\bibliography{foo.bib}</code> in <code>bar.tex</code>, <code>bibtex.exe</code> generates <code>\bibdata{foo.bib.bib}</code> in <code>bar.aux</code>. Anyway, I have <a href="https://github.com/yihui/tinytex/blob/4275a375c6/R/latex.R#L189-L196">patched this issue</a> in the R package <strong>tinytex</strong> for Windows users who use MiKTeX. TeX Live users don&rsquo;t suffer from this issue.</p>

<p>On this page, I&rsquo;ll let other users share their stories of installing and managing LaTeX. First I want to show a list of painful cases that I was aware of:</p>

<ul>
<li><p><a href="https://ubuntuforums.org/showthread.php?t=395863">Why LaTeX is such a bloated system?</a></p></li>

<li><p><a href="https://tex.stackexchange.com/q/43862/9128">Is there a lightweight implementation/distribution of TeX for Mac OSX?</a></p></li>

<li><p><a href="https://tex.stackexchange.com/q/81802/9128">Installing (a lightweight version of) latex on an external hard drive</a></p></li>

<li><p>texlive-full is <a href="https://github.com/rstudio/rticles/pull/130#issuecomment-313732003">too big</a>, <a href="https://github.com/rocker-org/rocker/issues/266">too big</a>, and <a href="https://github.com/road2stat/liftr/issues/25">just too big</a> for Docker images</p></li>

<li><p><a href="https://tex.stackexchange.com/q/18939/9128">Which LaTeX to install on Linux?</a></p></li>

<li><p>Missing LaTeX packages confuse users <a href="https://github.com/rstudio/rmarkdown/issues/359">forever</a>, <a href="https://github.com/rstudio/rmarkdown/issues/1076">forever</a>, <a href="https://github.com/rstudio/rmarkdown/issues/1393">forever</a>, and it takes <a href="https://tw.com/xieyihui/status/763805846807547904">forever</a> to figure them out and install. <a href="https://stackoverflow.com/q/47400936/559676">Error messages</a> can also be confusing. Sometimes we just <a href="https://github.com/rstudio/bookdown/issues/507">don&rsquo;t have a clue</a>.</p></li>

<li><p>When all you need is a LaTeX package, <strong>upquote</strong>, of which the size is 5K, <a href="https://github.com/jgm/pandoc/issues/2439#issuecomment-326518438">you have to install 500MB of additional software on Ubuntu/Debian</a>.</p></li>

<li><p>You may suffer from <a href="https://github.com/rstudio/rmarkdown/issues/1505">old bugs</a> that have been fixed in certain LaTeX packages.</p></li>

<li><p>MiKTeX <a href="https://github.com/rstudio/bookdown/issues/531">might fail</a> and we don&rsquo;t know what the error message &ldquo;GUI framework cannot be initialized&rdquo; means. Sometimes we have <a href="https://stackoverflow.com/questions/48892499/compile-rmarkdown-document-with-render#comment84801684_48892499">no clue</a> why it doesn&rsquo;t work.</p></li>
</ul>

<p>Below are stories and experiences contributed by other users:</p>

<blockquote>
<p>Removed TeX Live from my system (openSUSE): 1.5gb. Installed TinyTeX + the dependencies to compile my thesis: 150mb!!!! This is great!</p>

<p>&mdash; <a href="https://tw.com/brodriguesco/status/942162790587957248">Bruno Rodrigues</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Really liking the simplicity of tinytex package. Easy to get up and running to knit PDFs. No need for slow LaTeX install.</p>

<p>&mdash; <a href="https://tw.com/lingwhatics/status/941766989424537602">Daley Mikalson</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>A tiny LaTeX distribution easy to install from RStudio or on Travis CI is just what we needed!</p>

<p>&mdash; <a href="https://tw.com/PhilGrosjean/status/941241878309232640">Philippe Grosjean</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Seriously one of my only holdups teaching LaTeX in Rmarkdown (still taught it anyway) is now solved.</p>

<p>&mdash; <a href="https://tw.com/healthandstats/status/941169151749406720"> Tyson Barrett</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Tried TinyTeX with rmarkdown and both English and Chinese rendering. The most smooth experience ever using LaTeX!</p>

<p>&mdash; <a href="https://tw.com/renkun_ken/status/941352666730455041">Kun Ren</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>TinyTeX is awesome, if it had existed before I would have saved hours of my life spent dealing with LaTeX packages and failed R Markdown knits&hellip;</p>

<p>&mdash; <a href="https://github.com/rstudio/bookdown/issues/292#issuecomment-356480809">Antonio Vazquez Brust</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Many people don&rsquo;t realize that Texlive on some Linux systems (say you need a rstudio server) doesn&rsquo;t come with the TeX package manager. If the package you need is not in their system, you are basically screwed as you can&rsquo;t even install it. TinyTeX solves this problem and makes everything sweet and easy. Also, after using it for more than a month, I found the  messages of tinytex are very helpful, comparing with basically NULL in texlive.</p>

<p>&mdash; <a href="https://community.rstudio.com/t/texlive-distribution-on-centos-for-rstudio-server-and-connect/2916">Hao Zhu</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>I&rsquo;m a novice with R and I found the entire process of installing rmarkdown, knitr, MiKTeX, and pandoc and then reconciling all their directories very difficult. [&hellip;] The 3-4 hour detour into MiKTeX etc and how to produce PDFs was a frustration experience to say the least. (Up and running with TinyTeX five minutes later&hellip;)</p>

<p>&mdash; Justin Shapiro</p>
</blockquote>

<!-- -->

<blockquote>
<p>If you work in a locked down windows corporate enviroment and spent countless hours with MiKTeX or portable MiKTeX, you&rsquo;ll want to buy @xieyihui lunch.</p>

<p>&mdash; <a href="https://tw.com/ThomasSpeidel/status/957856056108920835">Thomas Speidel</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Too bad, this computer had a good month of TeX-free.</p>

<p>&mdash; <a href="https://tw.com/romain_francois/status/979022989634174976">Romain François</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>I&rsquo;d been avoiding installing LaTeX on my macOS and Windows machines b/c it&rsquo;s always such a hassle. Just learned about about TinyTeX today and easily got setup on both machines.</p>

<p>&mdash; <a href="https://tw.com/jdblischak/status/974066342780461056">John Blischak</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Like 2 hours later, I&rsquo;m not sure I want to know, but there <em>must</em> be a faster way of updating all my TeX packages than the ftp in TeX Live Utility&hellip;</p>

<p>&mdash; <a href="https://tw.com/dataandme/status/994531189217259521">Mara Averick</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Installing a complete version of MiKTeX is a freaking nightmare though. Don&rsquo;t know if it&rsquo;s my internet connection or what but I just can&rsquo;t get it all installed in one go. I finally just did the basic install and am selecting batches of pkgs at a time to add.</p>

<p>[&hellip;] I just installed this (TinyTeX) and it was SO EASY and I&rsquo;m kind of upset that I didn&rsquo;t know about it before. Gonna be shouting this one <a href="https://tw.com/swmpkim/status/1014546819085369344">from the rooftops</a>.</p>

<p>&mdash; <a href="https://tw.com/swmpkim/status/1014514680088399874">Kim Cressman</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Siri, how much of my life have I spent <a href="https://tw.com/djnavarro/status/1112674242523361281">installing TeX distributions</a>?</p>

<p>I have discovered that the tinytex package has handy tools for analysing the .log files, which solved my problems for me. That is, after I wasted half an hour trying to install MiKTeX for no good reason</p>

<p>&mdash; <a href="https://tw.com/djnavarro/status/1112687238196822016">Danielle Navarro</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>I used tinytex to upgrade TeX Live and install a package and it &hellip; worked. @xieyihui may have ended some of my LaTeX torment.</p>

<p>&mdash; <a href="https://tw.com/FanninQED/status/1146857305285242880">PirateGrunt</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>literally took me longer to remove all traces of MacTeX than to install TinyTeX and all the packages needed to build my thesis, and i saved about 10gb of disk space.</p>

<p>&mdash; <a href="https://tw.com/tjohnhos/status/1175575859748638720">Tim Hosgood</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>I&rsquo;ve always had a problem knitting to pdf with windows.  I followed instruction for tinytex and it works great now!</p>

<p>&mdash; <a href="https://tw.com/TexanDhillon/status/1183831526485712897">Dilsher Dhillon</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Learning to write a LaTeX manuscript  in R Markdown and was having problems loading new packages: tlmgr wasn&rsquo;t updating the packages. So, found the &ldquo;tinytex&rdquo; package that fixed everything.</p>

<p>&mdash; <a href="https://tw.com/dynamic_choice/status/1203389695419224064">Akash</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Just had to reinstall texlive on my Mac and once again, @xieyihui&rsquo;s tinytex package saves the day with tinytex::reinstall_tinytex().</p>

<p>&mdash; <a href="https://tw.com/ZKamvar/status/1202525888031657984">Zhian N Kamvar</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>Having just for fun installed R on my new Raspberry pi 4, I thought to myself now it would be nice to have latex, but really, all of texlive, probably not, so this was exactly what was needed. It installed for me immediately and &ldquo;just worked.&rdquo;</p>

<p>&mdash; <a href="/tinytex/#comment-4720783918">Roger Koenker</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>I&rsquo;ve always had problems knitting to pdf on Windows until I came across tinytex package.</p>

<p>&mdash; <a href="https://tw.com/dhillon_stats/status/1214204113359179779">Dilsher Dhillon</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>[&hellip;] uninstall MacTeX and install TinyTeX was the ticket! It FINALLY knit to pdf!!!!</p>

<p>&mdash; <a href="https://tw.com/TiffanyTimbers/status/1214344978769403905">Tiffany Timbers</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>[&hellip;] Why install 3GB of languages you don&rsquo;t know when all you want are beautiful tables?</p>

<p>&mdash; <a href="https://tw.com/RomanMLink/status/1227496566157524992">Roman Link</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>[&hellip;] Have you tried {tinytex}? It installs only what you need from LaTeX so you can knit to pdf! Changed my life!</p>

<p>&mdash; <a href="https://tw.com/swmpkim/status/1234517924028784640">Kim Cressman</a></p>
</blockquote>

<!-- -->

<blockquote>
<p>[&hellip;] R Markdown + library(tinytex) basically unlock all of the power of LaTeX without any of the headaches.</p>

<p>&mdash; <a href="https://tw.com/awunderground/status/1234665396654837761">Aaron R. Williams</a></p>
</blockquote>

        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>The R package tinytex</title>
      <link>/t/r/</link>
      <pubDate>Sun, 03 Dec 2017 00:00:00 +0000</pubDate>
      
      <guid>/t/r/</guid>
      <description>
        <![CDATA[
        

<p>You can install the <strong>tinytex</strong> package from either CRAN or Github:</p>

<pre><code class="language-r"># CRAN version
install.packages('tinytex')

# or the development version on Github
devtools::install_github('yihui/tinytex')
</code></pre>

<p>The package mainly provides two sets of functions: functions to manage TinyTeX, and those that help compile LaTeX documents to PDF.</p>

<h2 id="manage-tinytex">Manage TinyTeX</h2>

<p>The <code>tlmgr_*</code> family of functions calls the TeX Live utility <code>tlmgr</code> to manage TeX Live, e.g., install or update LaTeX packages. See <code>?tinytex::tlmgr</code> for the full documentation. The functions <code>tlmgr_search()</code>, <code>tlmgr_install()</code>, and <code>tlmgr_update()</code> may be the ones that you will most frequently use if you want to manage TeX Live by yourself.</p>

<h2 id="compile-latex-documents">Compile LaTeX Documents</h2>

<p>The &ldquo;loveliest&rdquo; feature of LaTeX is that you often have to compile a document multiple times to get the PDF, when you have cross-references (e.g., a bibliography or index).</p>

<p>A common reason for LaTeX to fail is missing LaTeX packages. Sometimes it is not straightforward to figure out which package is missing (certain packages may contain multiple <code>*.sty</code> or <code>*.cls</code> files). If you use pre-packaged TeX Live, this problem can be even worse. For example, on Debian/Ubuntu, LaTeX packages are grouped into collections and built to different Debian packages, so even only if one LaTeX package is missing, you have to install a big Debian package, which contains the package you need and possibly many other packages that you don&rsquo;t need.</p>

<p>The function <code>latexmk()</code> in <strong>tinytex</strong> tries to solve these two problems automatically. With a chosen LaTeX engine (<code>pdflatex</code>, <code>xelatex</code>, or <code>lualatex</code>), it compiles a LaTeX document three times by default, and also tries to install missing packages by default. The missing packages are detected from the LaTeX log via the function <code>tinytex::parse_packages()</code>.</p>

<p>You can change the maximum number of times to compile the document, and disable the automatic installation of missing packages. See <code>?tinytex::latexmk</code> for details.</p>

<p>The three function <code>pdflatex()</code>, <code>xelatex()</code>, and <code>lualatex()</code> are wrapper functions based on <code>latexmk()</code>. For example, <code>pdflatex()</code> is basically <code>latexmk(engine = 'pdflatex', emulation = TRUE)</code>.</p>

<p>The implementation is clumsy. Don&rsquo;t read the source code. I may not improve it in the future. I have wasted enough time on LaTeX, and a clumsy implementation should already save me a lot of time. Perfect is the enemy of good.</p>

<h2 id="debugging">Debugging</h2>

<p>If an error occurs when compiling a LaTeX to PDF, and the error message is not clear, you may try two things.
First, <a href="/en/2017/05/when-in-doubt-upgrade/">update all your R and LaTeX packages</a>:</p>

<pre><code class="language-r">update.packages(ask = FALSE, checkBuilt = TRUE)  # update R packages
tinytex::tlmgr_update()  # update LaTeX packages
</code></pre>

<p>If you see an error message like &ldquo;tlmgr: Remote repository is newer than local (2018 &lt; 2019)&rdquo; when updating LaTeX packages, it means your TinyTeX is too old now, and you need to reinstall it for a newer version:</p>

<pre><code class="language-r">tinytex::reinstall_tinytex()
</code></pre>

<p>If updating packages does not solve the problem, set the option in R:</p>

<pre><code class="language-r">options(tinytex.verbose = TRUE)
</code></pre>

<p>before you compile the document. If you are using R Markdown and the <code>Knit</code> button in RStudio, you should set the option in a code chunk in the R Markdown document.</p>

<pre><code class="language-md">```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
</code></pre>

<p>You can, and perhaps should, remove this option after you finish debugging (to silence LaTeX, because you no longer need to read the full log).</p>

<h2 id="other-latex-distributions">Other LaTeX distributions</h2>

<p>The <strong>tinytex</strong> package is not tied to TinyTeX, although (unsurprisingly) it should work best with TinyTeX. Specifically:</p>

<ol>
<li><p>The feature of automatically compiling a LaTeX document for a number of times until all cross-references are resolved is available to any LaTeX distributions, e.g., you can use MiKTeX on Windows if you want.</p></li>

<li><p>The feature of automatically installing missing LaTeX packages requires the LaTeX distribution to be TeX Live (remember, TinyTeX is a custom version of TeX Live, so TinyTeX also works). It also requires <code>tlmgr install</code> to be able to install packages. If you use a copy of TeX Live or TinyTeX installed by your system admin, and you are not given the privileges to modify it, this feature won&rsquo;t work for you. If you installed TinyTeX on your personal computer, chances are it will work. This feature is not available to MiKTeX users, but you won&rsquo;t need it, either, because MiKTeX itself can automatically install missing packages, too.</p></li>
</ol>

        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>TinyTeX 中文文档</title>
      <link>/t/cn/</link>
      <pubDate>Sun, 03 Dec 2017 00:00:00 +0000</pubDate>
      
      <guid>/t/cn/</guid>
      <description>
        <![CDATA[
        

<p>1TinyTeX 是一个瘦身版的 <a href="https://tug.org/texlive/">TeX Live</a>。TeX Live 的庞大体型问题<a href="/cn/2017/06/lightweight-texlive/">困扰我多年</a>，在 2018 年之前我终于抽出一周时间来解决这个问题，其实方案很简单：把对普通用户毫无用处的源代码和文档去掉即可。具体技术细节参见<a href="/tinytex/faq/">常见问题</a>，总体而言就是利用了 TeX Live 的自动化安装方式，配置文件中设置不要安装源文件和文档。</p>

<p>TinyTeX 假设你不惧怕或反感使用命令行，但其实需要的命令行指令并不复杂，常见任务都可以通过一行命令搞定。如果不清楚如何打开系统命令行窗口，请参见常见问题。</p>

<h2 id="安装">安装</h2>

<p>TinyTeX 的安装和维护对 R 用户来说最简单，两行 R 代码加上两到六分钟的等待时间：</p>

<pre><code class="language-r">devtools::install_github('yihui/tinytex')
tinytex::install_tinytex()
</code></pre>

<p>安装 TinyTeX 之前建议卸载系统中已有的 LaTeX 套件，如 TeX Live、MiKTeX、MacTeX 等。一个系统中最好不要有两个 LaTeX 套件同时存在，否则可能会产生冲突。</p>

<p>对其它用户，请参阅<a href="/tinytex/">首页</a>上的脚本安装方式，通常就是打开命令行窗口，运行一行命令即可。该命令会自动下载 TeX Live 的安装脚本并自动安装，由于是从网络下载安装 TeX Live，所以具体等待时间取决于网速。Unix 系统应该不会超过两分钟，Windows 系统可能需要五分钟左右（其间可能会弹出两次<a href="https://db.yihui.org/images/install-tl-win-lua.png">错误对话框</a>，点确定即可；如果杀毒软件弹出警告，请允许修改）。</p>

<h2 id="维护">维护</h2>

<p>TinyTeX 的主要维护工作应该是安装 LaTeX 包以及更新。如果编译 PDF 时出现缺失 LaTeX 包的错误信息，可以用命令行 <code>tlmgr search</code> 根据缺失文件名搜索包名，并用 <code>tlmgr install</code> 安装缺失的包；命令 <code>tlmgr update --self --all</code> 可以更新整个 TeX Live 系统。R 用户可以使用 <a href="/tinytex/r/">R 包 <strong>tinytex</strong></a> 中的相应函数，如：</p>

<pre><code class="language-r">library(tinytex)
tlmgr_search('framed.sty')  # 搜索包含 framed.sty 文件的 LaTeX 包
tlmgr_install('framed')     # 安装 framed 包
tlmgr_update()              # 更新 TeX Live
</code></pre>

<p>在 <strong>tinytex</strong> 包中还有一系列函数用来编译 LaTeX 文档，核心函数是 <code>latexmk()</code>，它主要是为了模拟 LaTeX 工具 <code>latexmk</code>，即：重要的 LaTeX 文档默认编三遍。如果你不懂这句话，那么恭喜你，不懂更好，不要在它上面浪费时间。还有另一个非常有用的功能，就是模拟 Windows 上 MiKTeX（当然现在 MikTeX 似乎并不局限于 Windows 了）：编译 LaTeX 文档过程中默认自动检测并安装缺失的 LaTeX 包。能自动化的都自动化，不必费劲去跑 <code>tlmgr search</code> 或 <code>tlmgr install</code> 之类的命令。</p>

<p>具体调用时，你可能会根据你需要的 LaTeX 引擎使用 <strong>tinytex</strong> 中的这三个函数之一： <code>pdflatex()</code>、<code>xelatex()</code>、<code>lualatex()</code>。看函数名应该就知道各自分别使用哪个 LaTeX 引擎。</p>

<h2 id="r-markdown-用户">R Markdown 用户</h2>

<p><strong>rmarkdown</strong> 包从版本 1.9 开始，编译 R Markdown 为 PDF 时会调用 <strong>tinytex</strong>，这样一来，R Markdown 用户的 LaTeX 世界应该就安静了：因为对 R Markdown 用户来说，编译 PDF 的头号出错可能就是缺失 LaTeX 包（Pandoc 翻译 Markdown 为 LaTeX 代码时，几乎不太可能产生 LaTeX 语法错误），而可怜的 R 用户哪能明白那错误消息是什么意思。</p>

<h2 id="结语">结语</h2>

<p>时间有限，中文文档只能写这么长；若有疑问，请参考首页以及常见问题。</p>

<p>LaTeX 排版很美丽，但它常让我们忘了自己的身份特么到底是作者还是排版工人；它就像一个永远长不大的孩子，没日没夜呼唤你的注意（唉哟，人家找不到 <code>framed.sty</code> 文件啦；哎呀，人家没法编出参考文献列表啦，请你看看你的 <code>.aux</code> 文件好不）。但愿这个 TinyTeX 套件以及 R 包 <strong>tinytex</strong> 能让它消停会儿。</p>

        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>Frequently (?) Asked Questions</title>
      <link>/t/faq/</link>
      <pubDate>Sat, 02 Dec 2017 00:00:00 +0000</pubDate>
      
      <guid>/t/faq/</guid>
      <description>
        <![CDATA[
        <p>This list of FAQs explain the technical details of TinyTeX for those who are curious, and alternative ways to install and use TinyTeX for those who are not sysadmins of their computers.</p>

<ol>
<li><p><strong>Which version of TeX Live is installed?</strong></p>

<p>The very latest. Using the very latest version of a software package can be risky. You have been warned. If you have to install an older version, you may consider using the service provided on <a href="https://texlive.info">texlive.info</a>. Specifically, you can find the possible versions by date at <a href="https://texlive.info/tlnet-archive/">https://texlive.info/tlnet-archive/</a>, and pass the URL of the <code>tlnet</code> directory to the <code>repository</code> argument of <code>install_tinytex()</code> if you install TinyTeX via the R package <strong>tinytex</strong>:</p>

<pre><code class="language-r">tinytex::install_tinytex(repository = 'https://texlive.info/tlnet-archive/2017/04/13/tlnet')
</code></pre>

<p>If you install TinyTeX using the installation script, set the environment variable <code>CTAN_REPO</code> to the URL of the appropriate <code>tlnet</code> directory before running the installation script.</p>

<p>Note that you can install the current latest version, and choose not to upgrade in the future if the version happens to be stable enough for you. However, this means you will not be able to install or update LaTeX packages after the current version of TeX Live is frozen (which happens annually).</p></li>

<li><p><strong>Do you provide prebuilt binaries of TinyTeX?</strong></p>

<p>No. Technically it is easy, but I don&rsquo;t really understand the implications of <a href="https://www.tug.org/texlive/LICENSE.TL">the TeX Live license</a>. Specifically, the license says:</p>

<blockquote>
<p>[&hellip;] TeX Live has neither a single copyright holder nor a single license covering its entire contents, since it is a collection of many independent packages.  Therefore, you may copy, modify, and/or redistribute software from TeX Live only if you comply with the requirements placed thereon by the owners of the respective packages.</p>
</blockquote>

<p>That sounds complicated to me. I don&rsquo;t have time to examine the license and terms of all these packages. Installing over the network is fast enough after all.</p></li>

<li><p><strong>What is the size of TinyTeX?</strong></p>

<p>About 150MB on macOS and Ubuntu, and 220MB on Windows (when installed). You may think it is still too big, but please consider that the size of <a href="https://www.tug.org/mactex/morepackages.html">BasicTeX</a> for macOS is about 215MB (when installed), and a <a href="https://miktex.org/download">basic MiKTeX installer</a> for Windows is about 750MB (I didn&rsquo;t check how big it is when installed).</p>

<p>If you create a tarball of TinyTeX on macOS or Ubuntu, it will be only 50MB. This can be very helpful if you install such a tarball on the cloud (e.g., for software testing purposes on Travis CI). The download and installation should take only a few seconds.</p>

<p>Of course, the size of TinyTeX will grow as you install more LaTeX packages.</p></li>

<li><p><strong>What does the TinyTeX installation script do exactly? How do you reduce the size of the gigantic TeX Live?</strong></p>

<p>The best way to understand TinyTeX is to <a href="https://github.com/yihui/tinytex/">read the source</a> under the <code>tools</code> directory. Basically, TinyTeX automates the TeX Live installation using a profile file named <a href="https://github.com/yihui/tinytex/blob/master/tools/tinytex.profile">tinytex.profile</a> (<code>./install-tl -profile=tinytex.profile</code>), which only specifies the <code>infraonly</code> scheme to be installed first. With this scheme, you cannot really compile any LaTeX documents, but it contains the most important utility <code>tlmgr</code> (TeX Live Manager). At this point, the total size is about 80MB.</p>

<p>Then I use <code>tlmgr</code> to install a few more commonly used packages (defined in <a href="https://github.com/yihui/tinytex/blob/master/tools/pkgs-custom.txt">pkgs-custom.txt</a>). With these packages, you should be able to compile most R Markdown documents to PDF. The total size becomes about 150MB.</p>

<p>The fact that I only included a small number of LaTeX packages in TinyTeX is one of the two reasons why TinyTeX is relatively small in size. The other reason is that I excluded the source files and documentation of packages. In <code>tinytex.profile</code>, you can see these two options:</p>

<pre><code class="language-config">option_doc 0
option_src 0
</code></pre>

<p>Why do I exclude source files? Because they are unlikely to be useful to end-users. Would you really read the source code of a LaTeX package? Probably not, unless you are a developer or advanced LaTeX user. In fact, this also explains why I don&rsquo;t provide prebuilt binaries of TinyTeX: some open-source licenses may require that you provide source files when you redistribute the open-source software. TinyTeX does not redistribute TeX Live, but only provides a custom installation script.</p>

<p>Why do I exclude the documentations? Tell me honestly: how many times have you found a solution via <a href="https://tex.stackexchange.com">StackExchange</a>, and how many times have you tried to read the package documentation? Even with the full documentation installed, you probably don&rsquo;t even know where to find these documentation files on your computer. The documentation files take a lot of disk space, and I believe they are rarely read by an average user, so they are not included. The address bar of your web browser is the most convenient documentation: type and search.</p>

<p>The other major factor that affects the size of TeX Live is the font packages, which are usually much bigger than other LaTeX packages, but we cannot really do much about it, unless you do not use <code>pdflatex</code>, in which case you may further reduce the size of this small TeX Live distribution.</p>

<p>You can use the command <code>tlmgr info --list --only-installed --data name,size</code> to obtain the sizes of all installed packages. If you have installed the R package <strong>tinytex</strong>, you can also use the function <code>tinytex::tl_sizes()</code>. For example, the size of the font package <strong>lm</strong> (Latin modern) is about 42MB!</p></li>

<li><p><strong>I&rsquo;m a Linux system admin. How can I install TinyTeX for all users of a system?</strong></p>

<p>First, add two options <code>--admin --no-path</code> to the installation script:</p>

<pre><code class="language-sh">wget -qO- &quot;https://yihui.org/gh/tinytex/tools/install-unx.sh&quot; \
  | sh -s - --admin --no-path
</code></pre>

<p>This will install TinyTeX to <code>~/.TinyTeX</code>, and this step does <em>not</em> require root privileges. Then you need to add symlinks to <code>/usr/local/bin</code> via <code>sudo</code>, so that all users of this system can use the TeX Live executables (e.g., <code>pdflatex</code>):</p>

<pre><code class="language-sh">sudo ~/.TinyTeX/bin/*/tlmgr path add
</code></pre>

<p><a href="https://github.com/yihui/tinytex/issues/37">Some systems</a> may set the permission of <code>~/.TinyTeX</code> to <code>700</code> by default, which means other users cannot really use TinyTeX (no permission to read, write, or execute anything in this directory). You may consider changing the owner or group of this directory using <code>chown</code>, and also granting write permission (plus execute permission on the subdirectory <code>bin</code>), e.g.,</p>

<pre><code class="language-sh">chown -R root:staff ~/.TinyTeX
chmod -R g+w ~/.TinyTeX
chmod -R g+wx ~/.TinyTeX/bin
</code></pre>

<p>If you want to move <code>~/.TinyTeX</code> to a different location, see FAQ 8, and remember to run <code>tlmgr path add</code> with <code>sudo</code> after you move the folder, to make sure symlinks under <code>/usr/local/bin</code> point to the the new paths correctly.</p></li>

<li><p><strong>I&rsquo;m a Linux admin. I used the above approach to install TinyTeX and added symlinks to <code>/usr/local/bin</code>. How can my users without root privileges install LaTeX packages by themselves?</strong></p>

<p>Users without root privileges won&rsquo;t be able to install packages via a normal <code>tlmgr install</code> command, unless you have assigned them to a group that has write permissions to the TinyTeX root directory (by default, <code>~/.TinyTeX</code>, and note that <code>~</code> is <em>your own</em> home directory), in which case these users are able to modify the system-wide installation of TinyTeX.</p>

<p>For those who do not have write permissions to the TinyTeX directory, there is a <a href="https://www.tug.org/texlive/doc/tlmgr.html#USER-MODE">user mode</a> in TeX Live that allows such users to manage a user-level texmf tree, e.g., a user can install packages to his/her home directory instead of a system directory. With TinyTeX, the user-level texmf tree is at <code>~/.TinyTeX/texmf-home</code> (in TeX Live&rsquo;s terms, this is the <code>TEXMFHOME</code> variable, and note that <code>~</code> is the <em>user&rsquo;s</em> home directory).</p>

<p>The first thing users have to do is to initialize the tree (create the <code>TEXMFHOME</code> directory if it does not exist). It only needs to be done once:</p>

<pre><code class="language-sh">tlmgr init-usertree
</code></pre>

<p>Then when they install packages, they must always use the option <code>--usermode</code>, e.g.,</p>

<pre><code class="language-sh">tlmgr --usermode install koma-script xcolor
</code></pre>

<p>For R users, the above commands are equivalent to:</p>

<pre><code class="language-r">tinytex::tlmgr('init-usertree')  # again, only do this once
tinytex::tlmgr_install(c('koma-script', 'xcolor'), usermode = TRUE)
</code></pre>

<p>However, the user mode of TeX Live can actually be quite complicated, and unfortunately it is not something that I can help with. A few known caveats:</p>

<ul>
<li><p>The worst thing is that users cannot install all packages. For TeX Live, some packages are <em>relocatable</em>, and some are not. For example, packages containing executables are not relocatable (e.g., the <strong>metafont</strong> package contains the executable <code>mf</code>). If users have to use these packages, only the system admin can help. The good news is that the number of such packages is relatively small, so a conservative strategy is to let the sysadmin just pre-install all of them.</p></li>

<li><p>Some packages may require running <a href="https://www.tug.org/texlive/doc/updmap.html"><code>updmap</code></a> after installation (e.g., font packages for <code>pdflatex</code>). Good news is that users should be able to run <code>updmap-user</code>, and bad news is that whenever the system admin runs <code>updmap-sys</code>, users may have to run <code>updmap-user</code> again (if I understand the documentation correctly). For users, the conservative stragety is to run <code>updmap-user</code> again when they run into font problems that didn&rsquo;t exist previously (R users can run <code>system2('updmap-user')</code>).</p></li>
</ul></li>

<li><p><strong>I&rsquo;m a Debian/Ubuntu user. How do I prevent TeX Live from being installed when installing other packages that depend on TeX Live? I don&rsquo;t want (or need) both TinyTeX and the official TeX Live packages to be installed at the same time.</strong></p>

<p>Yes, <code>apt-get install</code> might install certain <code>texlive-*</code> packages when they are dependencies of other packages (e.g., <code>apt-get install dvipng</code> will also install <code>texlive-base</code>). You can download and install <a href="https://travis-bin.yihui.org/texlive-local.deb">texlive-local.deb</a> to &ldquo;fool&rdquo; <code>apt-get</code>.</p>

<pre><code class="language-sh">wget &quot;https://travis-bin.yihui.org/texlive-local.deb&quot;
sudo dpkg -i texlive-local.deb
rm texlive-local.deb
</code></pre>

<p>This package was built by running <a href="http://manpages.ubuntu.com/manpages/trusty/man1/equivs-build.1.html"><code>equivs-build</code></a> on <a href="https://github.com/scottkosty/install-tl-ubuntu/blob/master/debian-control-texlive-in.txt">debian-control-texlive-in.txt</a> (credits to Scott Kostyshak). Basically it pretends all <code>texlive</code> packages have been installed (which is not true), so that you can have the full freedom (and responsibility!) of choosing which LaTeX packages to install by yourself.</p>

<p>Personally, I don&rsquo;t like the way that all LaTeX packages are distributed on Linux (e.g., Debian) as <code>texlive-*</code> packages, and each <code>texlive-*</code> package contains several LaTeX packages. That means you must install several other LaTeX packages even if you only need one. Imagine as an R user (or Python, or other languages): if someone prebuilds the more than 10,000 R packages on CRAN as 20 <em>collections</em> of packages, what do you feel when you only need the <strong>ggplot2</strong> package but are forced to install all possible packages related to data visualization? Obviously the advantage of providing these collections is that you may not need to install missing packages over and over again (who knows), but I&rsquo;d prefer a lean TeX Live distribution and install packages by myself (which is not difficult at all to me).</p></li>

<li><p><strong>Can I change the installation directory?</strong></p>

<p>The directory path is hard-coded in the installation script, and you cannot change it from the command line when installing TinyTeX. I chose these directories for Linux, macOS, and Windows because they are hidden by default on these platforms. TeX Live should not need (cry for) your attention in most cases. If you really want to change the directory, there are a few ways:</p>

<ul>
<li><p>You can download the installation scripts and modify them by yourself (in the spirit of open source).</p></li>

<li><p>If you are an R user, you can install the R package <strong>tinytex</strong>, and pass a custom directory name to the <code>dir</code> argument of <code>tinytex::install_tinytex()</code>.</p></li>

<li><p>Or install TinyTeX first, and move the installation folder to where you&rsquo;d like it to be (you can even move it to a USB stick). That is because TinyTeX is essentially a <em>portable</em> version of TeX Live. The tricky part of this way is to deal with the <code>PATH</code> variable. You need to run the command <code>tlmgr path add</code>, but <code>tlmgr</code> won&rsquo;t be on <code>PATH</code> if you have moved the default installation directory, so you have to execute <code>tlmgr</code> through its full path, e.g.,</p>

<pre><code class="language-sh"># assume you moved ~/.TinyTeX on Linux to /opt/tinytex
/opt/tinytex/bin/*/tlmgr path add
        
# assume you moved ~/Library/TinyTeX on macOS to /opt/tinytex
/opt/tinytex/bin/*/tlmgr path add
        
# assume you moved %APPDATA%\TinyTeX on Windows to C:\Software\TinyTeX
&quot;C:\Software\TinyTeX\bin\win32\tlmgr&quot; path add
</code></pre>

<p>You only need to do this once. If you installed TinyTeX using the approach in FAQ 5, you need <code>sudo</code> to run <code>tlmgr path add</code>.</p></li>
</ul></li>

<li><p><strong>How can I use TinyTeX on a USB drive or other portable devices?</strong></p>

<p>As I said, TinyTeX is a portable version of TeX Live, so you can simply copy it to a portable device. The only thing you need to do after you plug the device to another computer is run the command <code>tlmgr path add</code>. Again, you need the full path to <code>tlmgr</code> in your portable device (see the the previous FAQ). After you run this command and restart the application, you should be able to run <code>tlmgr</code> without its full path.</p>

<p>If you are an R user, the above steps can be done with two functions:</p>

<pre><code class="language-r"># copy an existing TinyTeX installation (to your portable device)
tinytex::copy_tinytex()
# tell me where TinyTeX is on your device, and I'll run
# tlmgr path add
tinytex::use_tinytex()
</code></pre>

<p>Note that TinyTeX installed on one platform will only work for the same platform, e.g., the Windows version only works for Windows. You cannot copy, for example, a macOS version of TinyTeX, and use it on a Windows machine.</p>

<p>This is a great way to get rid of IT or system admins. You don&rsquo;t have to request them to install or upgrade LaTeX packages for you. You can do everything by yourself.</p></li>

<li><p><strong>Why doesn&rsquo;t the default installation path contain the year of TeX Live?</strong></p>

<p>TeX Live installs itself to a directory named by the year by default (so does MacTeX), e.g., <code>/usr/local/texlive/2017</code>. I don&rsquo;t think it makes much sense to average users. Who would want multiple versions of TeX Live to be installed on the same computer except TeX Live developers? The full TeX Live is gigantic, and you probably do not want it to eat your disk space year by year.</p>

<p>Again, if you want to change the installation path of TinyTeX, you certainly can.</p>

<p>One TinyTeX user told me he was not aware of the fact that every year he actually installed TeX Live (MacTeX) to a different folder. If it were not for testing TinyTeX, he would never have discovered that he had got 15GB of TeX Live in several folders (like <code>/usr/local/texlive/2015</code>, <code>.../2016</code>, and <code>.../2017</code>, etc.). That confirmed my guess: users often do not know they installed a new version of TeX Live without uninstalling or overriding the installation from the previous year, so this monster just keeps growing every year. Yes, disk space is cheap nowadays, but that does not mean you have to waste it.</p></li>

<li><p><strong>How do I upgrade TinyTeX yearly after I had installed it in the previous year? I got a message like &ldquo;tlmgr: Remote repository is newer than local (2017 &lt; 2018)&ldquo;.</strong></p>

<p>You can install TinyTeX again, as the installation script always installs the very latest version. However, the currently installed LaTeX packages will be lost. If you want to reinstall these packages, too, you may use the R function:</p>

<pre><code class="language-r">tinytex::reinstall_tinytex()
</code></pre>

<p>If you do not use R, you can retrieve the list of packages and install them later:</p>

<pre><code class="language-sh">TL_INSTALLED_PKGS=$(tlmgr info --list --only-installed --data name | tr '\n' ' ')
# Then reinstall TinyTeX using the script on the homepage.
# After TinyTeX has been reinstalled, reinstall packages:
tlmgr install $TL_INSTALLED_PKGS
</code></pre></li>

<li><p><strong>Which LaTeX packages do I need to use the R package tikzDevice?</strong></p>

<p>To use the graphical device <code>tikzDevice::tikz()</code>, you need at these LaTeX packages:</p>

<pre><code class="language-sh">tlmgr install pgf preview xcolor
</code></pre></li>

<li><p><strong>I see a warning &ldquo;not verified: gpg unavailable&rdquo; every time when running <code>tlmgr</code>. How to get rid of this warning?</strong></p>

<p>As the message indicates, your system does not have <code>gpg</code> (GnuPG):</p>

<pre><code>tlmgr: package repository http://example.org/.../tlnet (not verified:
  gpg unavailable)
</code></pre>

<p>For TeX Live users on Windows and macOS, the easiest way to install <code>gpg</code> is probably <a href="http://www.preining.info/tlgpg/">http://www.preining.info/tlgpg/</a>. The &ldquo;one-time installation&rdquo; suffices.</p></li>

<li><p><strong>How can I install TinyTeX and/or LaTeX packages through HTTP/HTTPS/FTP proxies?</strong></p>

<p>You may create a <code>~/.wgetrc</code> file (<code>~</code> denotes your HOME directory), and add variables <code>http_proxy</code>, <code>https_proxy</code>, and/or <code>ftp_proxy</code> in it, e.g.,</p>

<pre><code class="language-config">http_proxy=http://user:password@proxy.example.com:8001/
</code></pre>

<p>See <a href="https://www.tug.org/texlive/acquire-netinstall.html">this page on tug.org</a> and <a href="https://www.gnu.org/software/wget/manual/html_node/Proxies.html">the documentation page of <code>wget</code></a> for more information.</p></li>

<li><p><strong>Can I use Homebrew to install TinyTeX on macOS?</strong></p>

<p>Yes, but there are no obvious advantages, so I don&rsquo;t really recommend this approach:</p>

<pre><code class="language-sh">brew install -v yihui/tinytex/tinytex
</code></pre>

<p>The formula is in the repo <a href="https://github.com/yihui/homebrew-tinytex">yihui/homebrew-tinytex</a> on Github. If you must use this approach, here are two caveats that you should know:</p>

<ul>
<li><p>Homebrew manages the symlinks of TeX Live (via <code>brew link tinytex</code>), and they are created under <code>/usr/local/bin</code>. You&rsquo;d better not run <code>tlmgr path add</code> afterwards, because this command creates symlinks to the same location. When you install a TeX Live package (via <code>tlmgr install</code>) that contains binaries, such as <strong>metafont</strong> (which contains the executable <code>mf</code>), you should run:</p>

<pre><code class="language-sh">brew postinstall tinytex &amp;&amp; brew unlink tinytex &amp;&amp; brew link tinytex
</code></pre></li>

<li><p>After you update <strong>tinytex</strong> in Homebrew (e.g., via <code>brew update &amp;&amp; brew upgrade</code>), the LaTeX packages that you previously installed by yourself will no longer be available, and you have to install them again. One solution is to <code>brew pin tinytex</code>, so that this formula won&rsquo;t be upgraded in the future (in fact, there should be no need to upgrade it). The other solution is to use the HEAD version of the formula:</p>

<pre><code class="language-sh">brew cleanup -s
brew remove tinytex
brew install -v --HEAD tinytex
</code></pre></li>
</ul>

<p>If you feel these issues are too complicated (yes they are), just follow the simpler way on the <a href="/tinytex/">homepage</a> to install TinyTeX on macOS.</p></li>

<li><p><strong>How to open a command window (terminal) to execute the commands you mentioned?</strong></p>

<p>I&rsquo;m not going to answer this question for Linux users. For macOS users, <code>Command + Space</code> to launch the Spotlight Search, and type <code>Terminal</code>. The first result should be <code>Terminal.app</code>. That is it. For Windows users, click the <code>Start</code> menu, select <code>Run</code>, and type <code>cmd</code>.</p>

<p>If you are an <a href="https://www.rstudio.com">RStudio</a> user, it can be easier. RStudio (&gt;= v1.1) has <a href="https://blog.rstudio.com/2017/08/11/rstudio-v1-1-preview-terminal/">built-in support for terminals</a>, and you can open a terminal right inside RStudio.</p></li>
</ol>

        
        ]]>
      </description>
    </item>
    
    
  </channel>
</rss>
