GithubHelp home page GithubHelp logo

doublez0108 / pkuthss-mac Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 3.0 41 KB

北京大学学位论文Latex模板(for Mac),基于pkuthss v1.9.1修改,主要进行Mac的适配修改、个人最佳实践说明、配置踩坑经验

Home Page: https://bbs.pku.edu.cn/v2/post-read.php?bid=346&threadid=18168137

Batchfile 0.96% TeX 99.04%
peking-university thesis-latex-template latex

pkuthss-mac's Introduction

北京大学学位论文Latex模板(for Mac)

本项目核心基于pkuthss 1.9.1版本,主要进行Mac的适配修改和个人最佳实践说明

🖋Mac+VSCode配置Latex环境

  1. 下载并无脑安装MacTex(将近5个G而且在外网)

  2. vscode安装Latex Workshop插件

    image.png
  3. 在设置中打开setting.json配置文件,然后添加这段配置代码

    配置代码
    "latex-workshop.latex.tools": [
      {
        "name": "xelatex",
        "command": "xelatex",
        "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "-pdf",
          "%DOC%"
        ]
      },
      {
        "name": "latexmk",
        "command": "latexmk",
        "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "-pdf",
          "%DOC%"
        ]
      },
      {
        "name": "pdflatex",
        "command": "pdflatex",
        "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOC%"
        ]
      },
      {
        "name": "bibtex",
        "command": "bibtex",
        "args": [
          "%DOCFILE%"
        ]
      },
      {
        "name": "biber",
        "command": "biber",
        "args": [
          "%DOCFILE%"
        ]
      }
    ],
    "latex-workshop.latex.recipes": [
      {
        "name": "xelatex -> biber -> xelatex*2",
        "tools": [
          "xelatex",
          "biber",
          "xelatex",
          "xelatex"
        ]
      },
      {
        "name": "xelatex -> bibtex -> xelatex*2",
        "tools": [
          "xelatex",
          "bibtex",
          "xelatex",
          "xelatex"
        ]
      },
      {
        "name": "xelatex",
        "tools": [
          "xelatex"
        ]
      },
    ],
    "editor.wordWrap": "on",
    "latex-workshop.view.pdf.viewer": "tab"

    注意这里有三种Recipes方式,第三种方式是最简单的直接使用xelatex编译,第一种第二种方式是针对不同项目中有参考文献的编译方法,总体上都是先编译第一次 -> 编译参考文献 -> 再编译两次

    在pkuthss项目中我们使用biber(第一种方式)进行编译

  4. 创建一个tex文件写点东西试一试

    \documentclass{article}
    \usepackage[UTF8, scheme = plain]{ctex}
    \begin{document}
    测试中文
    \end{document}
  5. 依次进行编译和预览

    image.png

    如果顺利看到pdf结果则证明latex环境安装顺利完成


📄编译pkuthss-mac

  1. clone该项目到本地

    git clone https://github.com/doubleZ0108/pkuthss-mac.git
    
  2. 在TEX标签下点击Recipe: xelatex->biber->xelatex*2进行编译

  3. 最终就得到了Mac+VSCode+pkuthss优雅写出来的论文啦🎉

    image.png

🧱从原pkuthss项目开始

编译pkuthss

  1. 直接下载最新pkuthss release版本即可

  2. 下载文件夹里pkuthss/doc/example/ 是之后自己写文章的部分,把这个文件夹单独拷贝到自己的目录下

  3. 把下载文件夹里pkuthss/tex/ 里的3个.def文件和1个.cls文件拷贝到上一步的example/里(别问我这步找问题找了多长时间)

  4. 修改example/ctex-fontset-pkuthss.def文件,这个文件的问题是原作者主要是在windows平台进行开发的,而由于windows和mac下字体名称不一样,导致编译时会报错The font xxx cannot be found.

    【解决办法】

    首先明确下两平台下的字体对应关系

    • win:simhei(黑体),simkai(楷体), simsun(宋体), simfang(仿宋)
    • mac:STHeiti (华文黑体),STKaiti (华文楷体),STSong(华文宋体) ,STFangsong(华文仿宋)

    以楷体的替换为例,在字体册中搜索楷体,这个STKaiti即是mac中对应simkai的那个字体

    image.png

    在这个文件里全局进行几种字体的替换即可

    还有网友说要修改/usr/local/texlive/[year]/texmf-dist/tex/latex/ctex/fontset/ctex-xecjk-winfonts.def 文件,但这样应该是直接修改了texlive的配置,大家也可以尝试

  5. 最终在命令行打开example/,然后通过latexmk命令进行编译,如果没有其他问题即可得到最终的pdf文件

  6. 在vscode中编译也类似的,直接Recipe: xelatex -> biber -> xelatex*2即可

    注意 如果没进行引用的话,在编译过程中会报错I found no \\citation commands---while reading file,添加\cite{}即可


🔧pkuthss中的一些设置问题

  1. 关于参考文献及引用

    🚪一扇任意门

    在这里踩的坑最多,先说最简单最原始的方法,直接将需要引用的文献BibTex放到thesis.bib中即可,然后在需要引用的部分\cite{name_of_citation}即可,在example中作者还给出了三种不同的引用样式:

    • \cite未格式化的 1
    • \parencite带方括号的 [2]
    • \supercite上标且带方括号的 [1,2]

    使用中还发现几个问题,第一是参考文献的样式不太对,按照要求把thesis.tex25行的biblatex改成如下即可,其中第二个参数是用来忽略出版社和出版地信息的,如果在参考文献中出现[S.l.]: [s.n.]则说明你需要添加这个配置

    \usepackage[backend = biber, gbpub=false, style = gb7714-2015]{biblatex}

    我个人在摸索的过程中需要实现的效果是每部分单独列出参考文献,并且希望连续编号,大致样式为

    This is chapter 1[1]
    
    参考文献
    [1] reference1
    
    -----
    
    This is chapter 2[2]
    
    参考文献
    [2] reference2
    

    在经过了两天漫长的踩坑和严谨的搜索后,终于找到了解决方案:

    \newrefsegment
    This is chapter 1\cite{reference1}
    \printbibliography[segment=\therefsegment]
    
    \newrefsegment
    This is chapter 2\cite{reference2}
    \printbibliography[segment=\therefsegment]

    如果想把『参考文献』四个字换成自定义的『MyName』,需要在\begin{document}前添加一段

    \defbibheading{myname}{
      \section*{MyName\ref{refsegment:\therefsection\therefsegment}}
    }

    然后在调用时\printbibliography[segment=\therefsegment, heading=myname]指定heading参数

    原项目通过\printbibliography一次性打印所有参考文献

    此外,在检索过程中还发现一些关键词可能对你有帮助:\begin{refsegment}, \bibbysegment

    其实有一种很简洁的平替方案

    \begin{refsection}
    \cite{reference1}
    \printbibliography
    \end{refsection}
    
    \begin{refsection}
    \cite{reference2}
    \printbibliography
    \end{refsection}

    但它的问题是不能接续编号,每个section都是从1开始编号,就为了这一点花了我太多时间踩坑了...

  2. 关于空白页面

    🚪又一扇任意门

    直接在模板里修改会发现几乎每一章/部分后面都有一个空白页面,对于不是要做毕设只是想用模板的同学来说非常抓狂

    一个简单的做法是在开头第一行加上openany参数 \documentclass[UTF8]{pkuthss},但仔细观察会发现奇数页的页眉是这个chapter的名字,但偶数页是一个固定的名称,大概是“北京大学硕士学位论文”类似的

    ~~这个问题暂时没有找到优雅的解决方案,我个人应急的方法如下:

    比如要去掉test.tex后的空白页,则在\input{test.tex}前加入这行

    \let\cleardoublepage\clearpage

    然后在每个章节tex文件\chapter的下方加入两行,这两行是指定这个页面的页眉信息

    \thispagestyle{fancy}
    \fancyhead[C]{Your Personal Title}

    这样可以解决不同页面上方页眉内容不一致的问题,但测试下来还有一个bug,如果这章超过了一页,则第二页的页眉页脚都会消失,暂时还没找到解决方案

    或者可以修改pkuthss.cls\fancypagestyle{plain}这部分代码,删掉其中关于twoside的部分,变为

    \fancypagestyle{plain}{
    	\fancyhf{}\renewcommand*{\headrulewidth}{0.75bp}
    	\fancyfoot[C]{\zihao{5}\normalfont{\thepage}}
    	\fancyhead[C]{\zihao{5}\normalfont\thss@int@setcase{\leftmark}}
    }
    \pagestyle{plain}

    关于页眉页脚的更详细设置可以搜索\pagestyle相关内容

  3. 有待发现和补充💭

pkuthss-mac's People

Contributors

doublez0108 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pkuthss-mac's Issues

字体缺失

我在编译的时候,提示字体缺失
具体如下:
Package fontspec: The font "STFangsong" cannot be found

请问这应该怎么解决呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.