LaTeX 笔记

Posted on Fri 09 January 2015 in misc

编译环境:XeTeX

每次都要翻以前的代码太麻烦了,干脆整理一下。随时更新。

  • 关于PDF阅读器

    zathura 是个不错的东西,界面简单,可以 continuous scroll,可以键盘操作,还支持 synctex。zathura-pdf-mupdf 后端目测比 zathura-pdf-poppler 后端好一点。

    vimtex 已经支持了zathura,无需单独配置,正确姿势请阅读VimTeX项目说明文档。以下配置仅供参考。

    let g:latex_fold_enabled = 0
    let g:latex_view_method = 'general'
    let g:latex_view_general_viewer = 'zathura'
    
    if empty(v:servername)
        let s:servername_option = ""
    else
        let s:servername_option = "--servername ".v:servername
    endif
    
    " Detect vim/gvim
    if has('gui_running')
        let s:vim_invoke_command = "gvim"
    else
        let s:vim_invoke_command = "vim"
    endif
    
    let g:latex_view_general_options = '-x '
                \ . '"'.s:vim_invoke_command.' '.s:servername_option
                \ . '--remote-send \"'
                \ . ':drop \%{input}:\%{line}:normal\! zzzv'
                \ . ':execute ''drop ''.fnameescape(''\%{input}'')'
                \ . ':\%{line}:normal\!  zzzv'
                \ . ':call remote_foreground('''.v:servername.''')\""'
    
    function! SyncTexForward()
        call latex#view#view('--synctex-forward='
                    \ . line(".") . ":"
                    \ . col(".") . ":"
                    \ . expand("%:p") . " "
                    \ . expand("%<") . ".pdf")
    endfunction
    nmap ls :call SyncTexForward()
    
  • vim退出插入模式后自动关闭输入法(fcitx有效)

    autocmd InsertLeave * silent! !fcitx-remote -c
    
  • PNG截图插入后大小不对的解决方法

    convert $f -density 96 -units PixelsPerInch $f
    

    请将96改成实际的屏幕DPI。注意:不要对同一张图片多次执行此命令!

  • 截图颜色反转(用于深色终端截图,节省墨水,从我做起)

    convert $f -negate $f
    
  • 两图并列

    \begin{figure}[h]
        \begin{minipage}{.5\textwidth}
            \centering
            \caption{pic1}
            \includegraphics[width=\textwidth]{pic1.jpg}
        \end{minipage}
        \begin{minipage}{.5\textwidth}
            \centering
            \caption{pic2}
            \includegraphics[width=\textwidth]{pic2.jpg}
        \end{minipage}
    \end{figure}
    
  • 字上横线

    \makeatletter
    \newcommand*{\txtoverline}[1]{$\overline{\hbox{#1}}\m@th$}
    \makeatother
    
  • 长得还不错的listing设置(不知道从哪抄来的)

    \DeclareCaptionFont{white}{\color{white}}
    \DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\linewidth}{\hspace{15pt}#1#2#3}}}
    \captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white,singlelinecheck=false,margin=0pt,font={bf,footnotesize}}
    
    \lstset{
        basicstyle=\small\ttfamily,
        numbers=left,
        numbersep=5pt,
        numberstyle=\ttfamily\color{gray},
        tabsize=4,
        extendedchars=true,
        breaklines=true,
        frame=b,
        showspaces=false,
        showtabs=false,
        xleftmargin=17pt,
        framexleftmargin=17pt,
        framexrightmargin=6pt,
        framexbottommargin=4pt,
        escapechar=`,
        showstringspaces=false,
    }
    
  • 中文章节名

    \usepackage{CJKnumb}  % for \CJKnumber{}
    \titleformat{\chapter}[display]{\Huge\bfseries}{\CJKnumber{\thechapter}}{1em}{}
    
  • 章节名后划线

    \titleformat{\chapter}[display]{\Huge\bfseries}{\CJKnumber{\thechapter}}{1em}{\Huge}[\vspace{2ex}\titlerule]