latex

latex

一、介绍

之前在windows上一直在使用ctex,基本上没什么问题。现在切换到Ubuntu上,平时基本上不会到Windows下了,想在Ubuntu上搭建起这个环境,方便以后使用。

xelatex提供了更好的Unicode中文支持,所以这里主要使用xelatex。
beamer模板可以快速进行PPT的制作。除了外表美观,还可以提高效率,我们只需要把自己的内容填进去只可以了。

二、安装

网上有许多教程:

  1. 安装texlive, ctex, xelatex, beamer
    sudo apt-get install texlive-latex-base
    sudo apt-get install latex-cjk-all
    sudo apt-get install texlive-latex-extra
    sudo apt-get install texlive-xetex 
    sudo apt-get install latex-beamer 
    
  2. 安装biblatex(3.11), biber(2.10),保持两者版本相适应
  3. 安装中文字体simhei, simsun, simkai, simfong

另外推荐texmaker这个软件,在Windows和Linux上都有,以前在Windows时就不喜欢自带的编辑器,到Ubuntu上发现texmaker还是那么好用。

三、beamer使用

  1. xelatex有时需要加上-shell-escape选项

  2. 中文支持

    \usepackage{xeCJK}
    \setCJKmainfont{SimSun}
    
  3. 插入代码
    beamer使用listings包插入代码,引入包并设置默认的代码格式::

    \usepackage{listings}
    \usepackage{xcolor}
    \usepackage{color}
    \definecolor{keywordcolor}{rgb}{0.8,0.1,0.5}
    \lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版
    \lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
    
    \definecolor{codegreen}{rgb}{0,0.6,0}
    \definecolor{codegray}{rgb}{0.5,0.5,0.5}
    \definecolor{codepurple}{rgb}{0.58,0,0.82}
    \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
    \lstset{language=C, %用于设置语言为C
        commentstyle=\color{codegreen},
        keywordstyle=\color{magenta},
        numberstyle=\tiny\color{codegray},
        stringstyle=\color{codepurple},
        basicstyle=\footnotesize,
        breakatwhitespace=false,         
        breaklines=true,                 
        captionpos=b,                    
        keepspaces=true,                 
        numbers=left,                    
        numbersep=5pt,                  
        showspaces=false,                
        showstringspaces=false,
        showtabs=false,                  
        tabsize=4,
        xleftmargin=2em,xrightmargin=2em, aboveskip=1em,
    %    frame=shadowbox
    }
    

    但编译时出错,而在document文件上就没有问题,发现需要在每帧ppt上加上fragile就可以避免这个问题:

    \begin{frame}[fragile]
    \frametitle{Test Code}
    \begin{lstlisting}[ language=C] 
    int main(int argc, char ** argv) 
    { 
        printf("Hello world!\n");
        return 0;
    } 
    \end{lstlisting} 
    
  4. 简单的模板

    \documentclass{beamer}
    \usetheme{Copenhagen}
    \usecolortheme{default}
    
      % 可供选择的主题参见 beameruserguide.pdf, 第 134 页起
      % 无导航条的主题: Bergen, Boadilla, Madrid, Pittsburgh, Rochester;
      % 有树形导航条的主题: Antibes, JuanLesPins, Montpellier;
      % 有目录竖条的主题: Berkeley, PaloAlto, Goettingen, Marburg, Hannover;
      % 有圆点导航条的主题: Berlin, Dresden, Darmstadt, Frankfurt, Singapore, Szeged;
      % 有节与小节导航条的主题: Copenhagen, Luebeck, Malmos, Warsaw
    
    %	color theme:
    % albatross crane beetle dove fly seagull wolverine beaver
    % inner color lily orchid rose
    % outter color whale seahorse dolphin
    
    %--------------------------------------
    % 中文字体 
    \usepackage{xeCJK}
    \setCJKmainfont{SimSun}
    
    %--------------------------------------
    % 代码
    \usepackage{listings}
    \usepackage{xcolor}
    \usepackage{color}
    \definecolor{keywordcolor}{rgb}{0.8,0.1,0.5}
    \lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版
    \lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
    
    \definecolor{codegreen}{rgb}{0,0.6,0}
    \definecolor{codegray}{rgb}{0.5,0.5,0.5}
    \definecolor{codepurple}{rgb}{0.58,0,0.82}
    \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
    \lstset{language=C, %用于设置语言为C
        commentstyle=\color{codegreen},
        keywordstyle=\color{magenta},
        numberstyle=\tiny\color{codegray},
        stringstyle=\color{codepurple},
        basicstyle=\footnotesize,
        breakatwhitespace=false,         
        breaklines=true,                 
        captionpos=b,                    
        keepspaces=true,                 
        numbers=left,                    
        numbersep=5pt,                  
        showspaces=false,                
        showstringspaces=false,
        showtabs=false,                  
        tabsize=4,
        xleftmargin=2em,xrightmargin=2em, aboveskip=1em,
    %    frame=single,
    %    framesep=3pt,%expand outward.
    %    framerule=0.1pt,%expand outward.
    %    xleftmargin=3.4pt,%make the frame fits in the text area. 
    %    xrightmargin=3.4pt,%make the frame fits in the text area.
    %	rulecolor=\color{red}
    }
    
    
    %--------------------------------------
    % logo
    \logo{\includegraphics[height=0.09\textwidth]{logo.png}}
    
    
    \begin{document}
    
    \title{xelatex+beamer处理中文} 
    \author{Thoms}
    \institute{XXX University...}
    \frame{\titlepage}
    
    
    \begin{frame} {你好,世界!}
    A displayed formula:
    
    $$  \int_{-\infty}^\infty e^{-x^2} \, dx = \sqrt{\pi} $$
    \begin{itemize}
    \item 成功编译tex文件
    \item 需要处理中英文混排时候的字体问题  
    \item 还需要处理公式中的字体问题
    \end{itemize}
    \end{frame}
    
    \begin{frame}[fragile]
    \frametitle{An Algorithm For Finding Primes Numbers.}
    
    代码如下:
    \begin{lstlisting}[ language=C] 
    int main(int argc, char ** argv) 
    { 
        /* this is comment */
        printf("Hello world!\n");
        return 0;
    } 
    \end{lstlisting} 
    
    \end{frame}
    \end{document}
    

5. 效果

latex
latex

posted @ 2019-05-03 16:01  bairuiworld  阅读(748)  评论(0编辑  收藏  举报