Total Pageviews

Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Sunday, 2 April 2023

在 Mac 上, 通过 Sublime 和 Skim 编辑 LaTeX

 Sublime Text 是一款非常优秀的编辑器:速度快,界面简洁,插件众多;并且能够跨平台使用,在 Mac 和 Windows 上都发挥完美。虽然是一款付费软件,但作者很厚道地给了无限期的试用期限。这一切正如其官网广告词说的那样:The text editor you'll fall in love with.
Skim 是一款免费轻量的 PDF 阅读、标注工具,布局贴心友好,与 OS X 自带的 Previewer 相比,Skim 能更好的注释 PDF 文件。
是一款权威的科技论文排版系统,不仅可以写论文,也可以处理日常的各种文档工作,甚至是做幻灯片。相比于 Microsoft Word,最大的优势是对于复杂公式的编辑与排版非常漂亮,并且用简单的命令就可以生成脚注、索引、目录和参考文献等复杂的结构。这一切优点都使得世界上众多的科学家们不再需要身兼作者与排版工两职,从而将更多的精力集中于文章内容本身。
本文的目的是将上述三种软件综合部署在 Mac 上。完成之后,你将可以在 Sublime Text 里面进行

代码编辑,用 Skim 预览生成的 PDF 文件。更重要的是,让你觉得,写论文也可以是一件很优美的事。

准备工作

  • Mac 上至少 4GiB 的空余空间
  • 高速的互联网连接

安装 MacTeX

  • 进入 MacTeX 官网下载 MacTeX.pkg 文件。文件大约 3GB,需要一段时间才能完成下载,趁现在去喝杯咖啡吧。
  • 下载完成之后,双击 MacTeX.pkg 进行安装。
  • 安装完成之后,会看到许多与 TeX 有关的程序图标,暂时忽略它们。

安装 Sublime Text

  • 进入 Sublime Text 官网下载最新版本的 Sublime Text 3。
  • 下载完成之后,将文件拖入应用程序文件夹安装。

安装 Package Control

我们需要在 Sublime Text 中下载插件以便能够很好地操作与

有关的文件。而插件是通过 Package Control 下载的。进入 Package Control 官网,按照提示进行安装即可。

如果网络连接有问题,也可以选择下载 Package Control.sublime-package 进行手动安装。安装完成后,退出并重启 Sublime Text。

安装 LaTeXBox 插件

  • Sublime Text 重启后,按下 Command+Shift+P 打开命令托盘(Command pallet),这一步也可以通过点击 Tools 下拉菜单完成。
  • 在命令托盘里输入 Install Package,按下 Enter 回车建。
  • 完成之后,输入 LaTeXBox,找到这一项并回车安装。
  • 退出并重启 Sublime Text。

安装 Skim

  • 进入 Skim 官网下载 Skim 并安装。
  • 打开 Skim,在菜单栏中点击 Skim > Preference(选项) > Sync(同步)
  • 在预设菜单中选择 Sublime Text
  • 关闭上面这个窗口。

修改编译和中文环境

现在,我们已经做完了所有的步骤✌️,可以打开 Sublime Text,Command+N 新建文件并在里面编写

代码了,完成编辑之后,Command+S 保存文件,Command+B 编译并运行,这时就可以在 Skim 里面看到 PDF 预览了。
如果你使用了 ctex,使用默认的编译配置可能会出现中文不正常的问题,这时需要进行手动设置,将默认的引擎设置为 xelatex。如图所示,打开:



然后输入以下内容:

{
"bring_forward_on_success": true,
"cmd": [
"latexmk", "-quiet", "-pdf", "-e",
"$pdflatex='xelatex -synctex=1 --shell-escape %O %S'"
],
}

如果使用 LaTeXBox 编译出现了其它问题,可以尝试在命令行中直接进行编译:在第一步完成后,打开终端,进入到 tex 所在到文件夹,使用 xelatex *.tex,编译 tex 文件为 pdf。如果成功,你可以将它添加到 Sublime Text 的 Build System 中,或者通过设置 LaTeXBox 的编译引擎,也可以实现一键编译。除此之外,还可以使用 Pandoc 等命令行工具将 tex 转为其他格式的文档。
在 Windows 上可以通过安装 TexLive 的方法配置 TeX 环境,过程是类似的。需要注意的是,tex 文件应采用 UTF-8 编码。

参考文章:在 Mac OS X 下搭建 Latex 编辑环境 

使用 Visual Studio Code 和 LaTeX Workshop 插件,可以获得更加友好的写作体验,不妨试一试

Tuesday, 15 March 2022

latex的一个使用例子

这是 《Linux-101-Hacks》这本书的中文翻译.

# build
 xelatex Chapter1.tex

from  https://github.com/hellojukay/Linux-101-Hacks

Tuesday, 1 March 2022

latex排版

我最初写博客都是使用的是Markdown1,后来写书也使用Markdown做简单排版。但一到出版社编辑那儿,就必须用Word了。也跟出版社聊过,是否可以用Latex排版,但出版社的答复是养一个Latex排版师太贵了,因此,作者们还是需要使用Word排版。

对于那些写小说或故事的作者,或许用Word排版还是不错的,但是,对于像我这样的技术人员,由于书中有很多代码和图表,用Word排版就比较累,尤其是技术人员好多都在用Mac,与Windows版的Word兼容性还比较差,写起来就更痛苦了。

使用Markdown格式写作,比Word要轻松多了,同时,使用一些辅助工具也能做到比较好的排版。如果万一有一天写出来的书能够正式出版,也希望Word是最后一步,把痛苦留到最后。

Word有一个功能确实不大好替代,那就是『修订』功能,使用它可以让作者和编辑很方便地交互修改文件。但文件传来传去也很烦。不知道一些在线的协作工具如石墨文档等,是否适合这种协作。

当然,其实作者不应该关注排版,而是在保证内容正确的前提下,把章节、强调、引用、代码之类的都标注出来即可,出版社是有专人进行排版的。而做这些标注,Markdown就够了。而且Markdown文件可以很方便地放到Git仓库中。我们不期望出版社所有的编辑也能熟悉Git,但如果真有哪天编辑们也喜欢Git了,那社会就真的进步了。

关于排版,本书主要讲一下相关的模板,以及一些排版原则:

  • 支持标准的Markdown,暂不支持各种扩展;
  • 使用开源字体;
  • 代码应该有单独的格式,用等宽字体,最好支持语法高亮;
  • 应该有移动版,目前大多数PDF并不适合在手机上阅读;
  • 移动版不应该首行缩进,因为页面太窄,缩进反而影响阅读体验;
  • 标准版应该首行缩进;
  • 印刷版应该奇偶页不同;
  • 提供Word版方便与其它人交流;
  • 还可以生成EPUB电子书等其它格式,欢迎提pr。

本书是可以『自举』的,也就是说你可以通过本书的源代码生成本书的PDF。参见:

https://github.com/seven1240/latex

最后,本书写作的目的并不是教你成为一个排版专家,相反,希望通过分享我的排版模板,让广大技术人员专注于用自己喜欢的工具写好自己的作品,忘记排版 ;)。

from https://github.com/seven1240/latex

-------------------------------------------------

编辑排版系统LaTeX

LaTeX是一款开源的编辑排版系统,由美国计算机学家莱斯利·兰伯特(Leslie Lamport)在20世纪80年代初期开发。基于TeX格式化引擎,LaTeX通过\section和\paragraph等语句,规定了每一句话在文章中所从属的层次,方便对各个层次批量处理。与Word相比较,LaTeX拥有方便美观的数学公式编辑、不会乱动的退格对齐。利用这种格式,可以方便生成复杂表格和数学公式,生成从简单的信件到完整书籍的各种类型的文档。

Tuesday, 19 December 2017

TexMaker的安装

TexMaker是一个针对LaTex编写的IDE软件, 免费, 提供以下功能:
  • 支持unicode
  • 自动补全(auto-complete)
  • 语法检查(lint)
  • 代码折叠(code folding)
  • 矩形选取(rectangular block selection)
  • PDF跟踪tex代码和同步
  • 正则表达式搜素替换
  • 检测日志文件自动定位错误和警告

安装

  • 首先要安装LaTex, 一般推荐使用套件.
    • Window下一般首选MikTex, 下载页面安装Basic版本即可.一直默认安装完后就会自动设置环境变量. 现在官网推荐安装proTeXT, 基于MikTex增强版吧.
    • Mac下可以安装MacTex, Linux下可以安装Tex Live. MacTex是Tex Live的Mac上增强版. MacTex比较大, 慢慢下载吧, 不知道啥时候能够选择性下载简化版..
      Mac安装后会有一系列的程序, 包括:
      • TexWorks: 跨平台编辑器. 更多编辑器比较.
      • TexShop: Mac上的编辑器
      • BibDesk: Mac使用的文献管理工具, 方便与BibTex交互.
      • LaTexiT: 一个简易的Latex公式编辑器, 生成公式后可以方便地黏贴到PPT/Word里头.
      • Excalibur: Mac上Latex进行语法检查的程序.
      • TeX Live Utility: 一个控制MacTex升级, 组件控制, 整体设置, 包管理的应用.
  • 下载TexMaker. 安装. 如果先安装TexMaker, 环境变量不一定有latex, 需要关掉程序再打开. 如果没有装MikTex, 则功能不能用. 如果环境变量不正常, 需要自行设定环境变量.

设置

  • 默认一般即可, 主要是latex和pdflatex.
  • pdf viewer. 默认使用嵌入自带pdf浏览器, 还可以设置弹出自带浏览器(去选择Embed), 外部浏览器. 建议使用默认, 可以跟踪内容. PDF viewer有些机器装了后看不到..此时需要拖动窗口边缘放大才能正常显示出来…小bug一个.正常显示像下面所示:


如何在 Mac OS X 上裝設 LaTeX 以及 CJK 套件 (TeX Live 2007)

Friday, 27 January 2017

bibtex2html


bibtex2html is a collection of tools for translating from BibTeX to HTML. They allow to produce, from a set of bibliography files in BibTeX format, a bibliography in HTML format. Here are some features:
  • Handle any BibTeX style (even those producing multiple bibliographies);
  • Use additional fields like abstract, url, ps, etc. to insert web links;
  • Crossrefs are also replaced by links;
  • Sort by dates or authors, in increasing or decreasing order;
  • Read simple macros in TeX or LaTeX files;
  • Show syntax errors in BibTeX files;
  • Extract from one or several BibTeX files the set of entries satisfying a given criterion.

Examples

The simplest is to look at an example. And here is another with my own bibliography.

Documentation

On-line documentation or in PDF format. Note for users using a version of bibtex2html prior to 1.98: TeXlive 2010 prevents bibtex2html to run bibtex in a temporary directory, resulting in an error message such as
  bibtex: Not writing to /var/folders/Ub/Ubo4JLWw2RWgeU+1YuiY3U+++TM/-Tmp-/bib2html67bb78.blg (openout_any = p).
  I couldn't open file name `/var/folders/Ub/Ubo4JLWw2RWgeU+1YuiY3U+++TM/-Tmp-/bib2html67bb78.blg'
  error 1 while running bibtex
A workaround consists in telling bibtex2html to use the current directory for temporary files, using the following shell command before running bibtex2html:
  export TMPDIR=.

Distribution

bibtex2html is written in OCaml and is freely distributed, under the terms of the GNU GENERAL PUBLIC LICENSE. bibtex2html requires that bibtex is installed. bibtex2html is hosted on github.
The current version is 1.98 and can be downloaded from here. See the CHANGES. The distribution includes:

Ressources

A collection of BibTeX style files and related scripts, contributed by some bibtex2html users, is available here. See for instance Mario Valle's publications and the associated script,
or John Owens's publications and the associated script.

Authors

Jean-Christophe Filliâtre and Claude Marché.
Ralf Treinen contributed the aux2bib tool and the Debian package. Coments and bug reports: mail us (sending us the BibTeX file which produces the bug if possible).
Thanks to Xavier Leroy and Thomas Ruedas for their help.

Related HTML tools

HeVeA
A powerful and highly configurable LaTeX to HTML converter.
 
from  https://www.lri.fr/~filliatr/bibtex2html/

Thursday, 26 January 2017

Write well-formed documents with LaTeX

LaTeX is an awesome tool. It allows writing well-formed documents with no efforts. You can manage your references, your bibliography, your acronyms and a lot more.

LaTeX installation

There are two different ways to install LaTeX. First, the basic installation with nothing more than the few main packages. LaTeX is a modular system, each functionality is in a package and you can install them separately. But it’s a lot of pain to fix compilation issues when some package is missing and it’s really time-consuming. On the other hand you can install the full LaTeX pack. It’s the LaTeX compiler with every well-known packages so it’s really big (a few Go). The choice of one method over the other is just about the size of your disk.

Functionalities

Language specific typography

LaTeX will take care of adding typographical spaces where needed. It’s really useful, especially in language like French where you need to add thin non-breaking spaces before a lot of punctuation signs.

Images

LaTeX can be really useful with images, except the verbosity of the code.
\begin{figure}
  \centering
  \includegraphics[width=0.5\textwidth]{image.png}
  \caption{Title of the image.}
  \label{label-of-the-image}
\end{figure}
To include an image, you need to use the \includegraphics command with some options and the name of your file. To provide a title and a label (useful for references), you need to wrap the image in the figure environment. Finally, you need to specify the \centering command because it’s not the default in LaTeX.
One thing to know with LaTeX is you don’t have a lot of control about where your image will be rendered: it could be just after the text, just before or two-page away. It’s an advantage because you don’t have to bother about the placement of your pictures and it forces you to use the good practice of referencing all your pictures in your text (use “figure 2.1” instead of “below” or “right after”). The main problem here is when you have highly visual documents with figures not only here to help the comprehension of your text but also with a real meaning. It can be annoying to switch between pages to read the document. In these cases, LaTeX may not be the most suitable tool to write your report.

References

One of the most useful feature of LaTeX is the references. It allows you to add labels in your text and use them to link to some parts of your document. LaTeX will replace the command \ref{a label} with the according number of the chapter, section or figure. If a label is missing, you can easily find it out looking for ?? in your PDF (or in the ugly LaTeX logs ^^). Of course, every reference is a real link in the PDF to jump to the referring section. If you add a chapter, every reference stay up-to-date without any modification.

Bibliography and glossary

Who never run into this problem of unused abbreviation or bibliography? LaTeX can help you in these cases. For the bibliography, you just need to specify all your sources and then use them in the text. BibTeX will take care of everything else.
@Misc{documents-with-latex,
  author = {Thibaud Dauce},
  title = {Write well-formed documents with LaTeX},
  howpublished = {\url{https://thibaud.dauce.fr/posts/2015-12-06-write-well-formed-documents-with-latex.html}},
  month = {December},
  year = {2015},
}
This is an example of entry in a BibTex file. You can use this entry in your document with the \cite command, for example:
Thibaud thinks \LaTeX is awesome \cite{documents-with-latex}.
If one of the entry of your bibliography is not used anymore in your document, it will not be printed at the end. The same concept works with the glossary. You just need to define all your acronyms and definitions:
\newacronym[longplural={Frames per Second}]{fpsLabel}{FPS}{Frame per Second}
and use it:
My camera is recording at 30 \glspl{fpsLabel}.
If it’s the first use of the acronym, LaTeX will show the full name and after that he’ll use the acronym only in the document. A lot of options and configuration are available in the documentation.

Syntax highlighting

You can use the Python package pygments and the LaTeX package minted to add syntax highlighting in LaTeX. To use it, you need to install pygments:
yaourt -S python-pygments
Then you can compile your document with the -shell-escape flag to allow the LaTeX compiler to run system commands and that’s it!

LaTeX generator

I recently discover there was a Yeoman generator for LaTeX named generator-latex available on Github. The source code is a bit old and I didn’t use it yet on a real project but it seems promising. The creation of the LaTeX boilerplate can be really long and I often copy paste old projects. This generator could be really awesome. It includes grunt, a NodeJS build tool to compile the project each time there is a modification on files and a live-reload of the PDF in the browser.

Conclusion

It was a really just an introduction to all the features available with LaTeX. Write documents with LaTeX is harder than in Markdown or in LibreOffice but it brings a lot of very useful features.
The compilation logs of LaTex are awful but the documentation is really great with a lot of examples and explanations.

from  https://thibaud.dauce.fr/posts/2015-12-06-write-well-formed-documents-with-latex.html