记录 $\LaTeX$ 使用中的问题和解决方案

主要涉及本人在 LATEX 使用中遇到的问题和解决的办法,不定期更新。 目前打算的内容有:

  1. 软件的选择 ,包括编译环境、编辑器的安装与配置。
  2. 中文环境的解决方案
  3. LATEX 写作中的技巧、问题的汇编整理

软件的选择

主要是在Windows、MacOS系统下使用,偶尔在Linux平台(Ubuntu)下使用。因此所有使用软件都以跨平台为基础标准。目前使用的是Atom+TexLive的组合(以前一直用Sublime+TexLive,但Sublime Text 在Ubuntu平台的中文输入法很让人头疼,加上其他一些原因,放弃)

编译环境

常用的应该是MikTex和Texlive两类。中文Ctex套装中封装的是MikTex。但TexLive在Linux和Mac平台都有对应的支持(此处有误,Mac下为Macshop,编辑器为TexShop,参见中文版LaTeX排版)。在Windows平台下选择两者皆可。 在Windows平台下,我同时安装了两种软件,编译时选择任何一个即可。Windows平台下的安装没有什么难度。

Ubuntu下安装TexLive

将来补充

TexLive的后续配置
1.中文显示问题

在tex文件中加入

\usepackage{ctex}

并且使用xelatex的编译方式(通常为pdf LATEX )。

2.local sty files 如何全局使用的问题。

参见StackExchange中这个问题的讨论 Where do I place my own .sty or .cls files, to make them available to all my .tex files?

There are two parts to telling TeX about a new .sty file. First, you have to put it in the 'right' place and second you need to update the database TeX uses to find files. The place to put the file depends on your operating system. Assuming you have a standard installation, this will probably be:

- Windows 10 (and miktex)
    C:\Users\<user name>\Appdata\Local\MikTex\<number>\tex\$\LaTeX$\local\
- Windows Vista/7
    C:\Users\<user name>\texmf\tex\$\LaTeX$\local\
- Windows XP
    C:\Documents and Settings\<user name>\texmf\tex\$\LaTeX$\local\
- Linux
    ~/texmf/tex/$\LaTeX$/local/
- Mac OS X
    /Users/<user name>/Library/texmf/tex/$\LaTeX$/local/

Note: the local/ folder might not exist; in this case, go ahead and create it.

也就是说,texlive会自动的识别一些特殊的路径作为local .bst文件,.sty文件的存放位置。对应的在C:\Users\

\texmf\tex$\LaTeX$\local\ 这里建立起来各层路径,将对应的sty文件bst文件放入后,就可以在所有本机的tex文档中调用了。

此外,在texmf路径下,还拷贝了其他文件夹,包括:

  • bibtex
  • doc
  • dvips
  • fonts
  • metapost
  • tex
  • tlpkg
  • web2c 用于存放不同类型的数据。

代码编辑器

主要选择了Atom作为编辑器,可以很好的支持Git,同时拥有很多扩展。

Atom安装

没有技术难度

LATEX 相关的高效率package
  • 代码高亮:language-latex
  • 直接编译: LATEX
  • 预览pdf:pdf-view (synctex也就是从双击pdf中的位置链接到tex文档中对应位置的功能目前有问题,暂时没用)

相关的重要设置:

  1. language-latex: 无
  2. LATEX :

    • 安装: apm install latex 安装(在cmd下)–>
    • 配置:1.打开setting-packages-latex,在cleanpattern中增加想要清理时删除的文件(例如.log, .aux等,在这个package下可以快速删除);2.在opener中选择Sumatra,并填入Sumatra中对应的路径,在cleanpattern中增加想要清理时删除的文件(例如.log, .aux等,在这个package下可以快速删除);3.在opener中选择Sumatra,并填入Sumatra中对应的路径。Sumatra事先安装好,将安装路径加入系统变量Path中,在Sumatra中配置发现搜索的命令:”C:\Users\Sean\AppData\Local\atom\app-1.21.1\atom.exe” “%f:%l”。
    • 使用快捷键,Ctrl+Alt+b编译文件,Ctrl+Alt+c清除无用文件(在clear pattern中设定)
    • 效果:编译后,在Sumatra中打开pdf文件,并且实现了反向搜索。

LATEX 写作中的技巧、问题的汇编整理

  1. 特殊符号

    1. #### LaTeX符号, 输入如下即可:
    $\LaTeX$
  2. 数学公式

  3. beamer

  4. notes

    主要是使用package todonotes 例如,可以参考StackExchange中的这个问题的讨论: How to add todo notes?

    The todonotes package mentioned above can be customized to show various types of notes. It is also possible to create a summary of all notes, for example at the end of the document. Here is an example:

     \documentclass{article}
     \usepackage{lipsum}                     % Dummytext
     \usepackage{xargs}                      % Use more than one optional parameter in a new commands
     \usepackage[pdftex,dvipsnames]{xcolor}  % Coloured text etc.
     %
     \usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}
     \newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
     \newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
     \newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}
     \newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}
     \newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}
     %
     \begin{document}
      >  \pagestyle{empty}
      >  \todo[inline]{The original todo note withouth changed colours.\newline Here's another line.}
      >  \lipsum[11]\unsure{Is this correct?}\unsure{I'm unsure about also!}
      >  \lipsum[11]\change{Change this!}
      >  \lipsum[11]\info{This can help me in chapter seven!}
      >  \lipsum[11]\improvement{This really needs to be improved!\newline\newline What was I thinking?!}
      >  \lipsum[11]
      >  \thiswillnotshow{This is hidden since option `disable' is chosen!}
      >  \improvement[inline]{The following section needs to be rewritten!}
      >  \lipsum[11]
      >  \newpage
      >  \listoftodos[Notes]
      >  \end{document}

    Note: LATEX 命令\lipsum是生成随机文本的意思 Notice the \thiswillnotshow note which is disabled using the disable option in the header. This can be used to turn off each type of note globally. Todonotes can also be used in the caption of tables and figures, though only provided that the inline option is used with these notes.

    You can also add a todo note with an incrementing counter for each note, using the following code: \newcounter{todocounter} \newcommandx{\todocount}[2][1=]{\stepcounter{todocounter}\to‌​do[linecolor=YellowG‌​reen,backgroundcolor‌​=YellowGreen!25,bord‌​ercolor=YellowGreen,‌​#1]{\thetodocounter: #2}}

但如果是要递增counter,可以参考Sharpe Ratio project中的写法,这里实现了三个人可以分别点评

\documentclass[12pt]{article}
\usepackage{amssymb,amsmath}
\usepackage{graphicx}
%\usepackage{epsfig}
\usepackage{float}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{placeins}
\usepackage{threeparttable}
\usepackage{pdfpages}
\usepackage{lscape}
\usepackage{marginnote}      % Used with todonotes package
\usepackage{datetime}           % Allows formatting of date and time
\usdate                         % Use usual LaTeX date layout
\usepackage{enumitem}           % List formatting commands
\setlist{noitemsep}             % Remove space between list items
\usepackage{subfigure}          % Create numbered and captioned subfigures
\usepackage{rotating}           % Create landscape tables and figures
\usepackage{epsfig}
\usepackage{epstopdf}
\usepackage[hidelinks, colorlinks=false, urlcolor=blue,citecolor=black]{hyperref}           % URLS and hyperlinks
\usepackage{longtable}
\usepackage{indentfirst}
\usepackage{appendix}
\usepackage[font=large,labelfont=bf,up,textfont=small, justification=justified,singlelinecheck=false,up]{caption}
\usepackage{fancyhdr}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{supertabular,booktabs}
\usepackage{array}
\usepackage[longnamesfirst]{natbib}
\usepackage{xcolor}
\usepackage{authblk}
\usepackage{versionPO}          % Include text conditionally
\usepackage{subfigure}
\usepackage{mathtools, cases}

\includeversion{notes}   % Include notes?
%\excludeversion{notes}
\excludeversion{comment}
\includeversion{links}          % Turn hyperlinks on?
% \includeversion{submit}   % Format for conference submission?
\excludeversion{submit}   % Format for conference submission?
%\includeversion{toc}   % Include table of contents?

% Turn off hyperlinking if links is excluded
\iflinks{}{\hypersetup{draft=true}}


% Notes options
\ifnotes{%
\usepackage[margin=1in,paperwidth=10in,right=2.5in]{geometry}%
\usepackage[textwidth=1.4in,shadow,colorinlistoftodos]{todonotes}%
\usepackage{menukeys}
}{%
\usepackage[margin=1in]{geometry}%
\usepackage[disable]{todonotes}%
}

% Define commands for making a table
\newcolumntype{P}[1]{>{\raggedright}p{#1}}
\newcommand{\tn}{\tabularnewline}

% Define note commands
\newcommand{\smalltodo}[2][] {\todo[caption={#2}, size=\small, fancyline, #1] {\begin{spacing}{.5}#2\end{spacing}}}
\newcommand{\rhs}[2][]{\smalltodo[color=red!30,#1]{{\bf YT:} #2}}
\newcommand{\rhes}[2][]{\smalltodo[color=green!30,#1]{{\bf CJ:} #2}}
\newcommand{\rhfs}[2][]{\smalltodo[color=blue!30,#1]{{\bf XX:} #2}}
\newcounter{todocounterYT}
\newcounter{todocounterCJ}
\newcounter{todocounterXX}
\newcommand{\YT}[2][]{\stepcounter{todocounterYT}\rhs[#1]{\thetodocounterYT:#2}}
\newcommand{\CJ}[2][]{\stepcounter{todocounterCJ}\rhes[#1]{\thetodocounterCJ:#2}}
\newcommand{\XX}[2][]{\stepcounter{todocounterXX}\rhfs[#1]{\thetodocounterXX:#2}}

\newcommand{\rhsnolist}[2][]{\smalltodo[nolist,color=green!30,#1]{{\bf YT:} #2}}
\newcommand{\rhsfn}[2][]{%  To be used in footnotes (and in floats)
\renewcommand{\marginpar}{\marginnote}%
\smalltodo[color=green!30,#1]{{\bf YT:} #2}%
%
% \newcommand{\rhsnolist}[2][]{\smalltodo[nolist,color=green!30,#1]{{\bf XX:} #2}}
% \newcommand{\rhsfn}[2][]{%  To be used in footnotes (and in floats)
% \renewcommand{\marginpar}{\marginnote}%
% \smalltodo[color=green!30,#1]{{\bf XX:} #2}%

\renewcommand{\marginpar}{\oldmarginpar}}
\newcommand{\textnote}[1]{\ifnotes{{\colorbox{yellow}{{\color{red}#1}}}}{}}
\renewcommand{\marginpar}{\marginnote}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\makeatletter\let\chapter\@undefined\makeatother % Undefine \chapter for todonotes.
  1. ### hyperlink

未完待续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值