hushidong / biblatex-gb7714-2015

A biblatex implementation of the GB/T7714-2015 bibliography style || GB/T 7714-2015 参考文献著录和标注的biblatex样式包
742 stars 83 forks source link

使用 quarto 生成 pdf 参考文献的等字显示为 “andotherscn” #204

Closed jchliao closed 1 month ago

jchliao commented 1 month ago

使用 quarto 生成 pdf 参考文献的等字显示为 “andotherscn”

yaml配置

format:
  pdf:
    documentclass: article
    papersize: a4
    geometry:
      - top=1in
      - left=1.25in
      - heightrounded
    indent: 2em
    linestretch: 1.5
    toc: true
    toc-depth: 3
    number-sections: true
    colorlinks: false
    tbl-colwidths: auto
    tbl-cap-location: top
    fig-pos: 'H'
    fig-cap-location: bottom
    monofont: Consolas
    code-block-bg: "f1f3f5"
    # code-block-bg: lightgray
    # code-line-numbers: ture
    # listings: true
    keep-tex: true
    include-in-header:
      text: |
        \usepackage{ctex}
        \usepackage{amsthm,mathrsfs}
        \usepackage{arydshln}
    cite-method: biblatex
    biblio-style: gb7714-2015
crossref:
    eq-prefix: ""
jupyter: python3

image

hushidong commented 1 month ago

是不是应该还有一个 cite-style?

我没用过这个quarto ,有个疑问,为什么biblatex不和amsthm等一样的用法呢? 使用usepackage?

hushidong commented 1 month ago

比如直接用:

\usepackage[style=gb7714-2015]{biblatex}

jchliao commented 1 month ago

quarto 的 cite-method 有 citeproc, natbib, or biblatex这三个 可以把[@ref]这个语法转化为对应的语法生成.tex文件。 直接用\usepackage[style=gb7714-2015]{biblatex}还是会有andotherscn 现在用

    include-in-header:
      text: |
        \usepackage{ctex}
        \usepackage{amsthm,mathrsfs}
        \usepackage{arydshln}
        \usepackage[sort&compress]{gbt7714}
    cite-method: natbib
    biblio-style: gbt7714-numerical

能用了,就是上标和正文需要 \citestyle{super}\citestyle{numbers}切换

hushidong commented 1 month ago

你能把使用biblatex时的信息给的更全面一些么? 你这个qurato下安装的texlive是什么版本,biblatex什么版本?biblatex-gb7714-2015什么版本? 转换出来的tex文件什么样的?

你最好打个包,告诉我怎么复现这样一个问题。

hushidong commented 1 month ago

我猜,虽然使用了biblatex,但没有使用biber,所以应该给出biblatex的backend选项。

就是 https://quarto.org/docs/output-formats/pdf-basics.html 里面提的 biblatexoptions 选项。

或者直接使用:

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

jchliao commented 1 month ago

quarto 使用 pandoc 导出 tex 文件,然后编译tex的log是这样的

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

generating bibliography
  INFO - This is Biber 2.19
  INFO - Logfile is '1_copy.blg'
  INFO - Reading '1_copy.bcf'
  INFO - Found 3 citekeys in bib section 0
  INFO - Processing section 0
  INFO - Looking for bibtex file 'references.bib' for section 0
  INFO - LaTeX decoding ...
  INFO - Found BibTeX data source 'references.bib'
  INFO - Overriding locale 'chinese-hans' defaults 'normalization = NFD' with 'normalization = prenormalized'
  INFO - Overriding locale 'chinese-hans' defaults 'variable = shifted' with 'variable = non-ignorable'
  INFO - Sorting list 'none/global//global/global' of type 'entry' with template 'none' and locale 'chinese-hans'
  INFO - No sort tailoring available for locale 'chinese-hans'
  INFO - Writing '1_copy.bbl' with encoding 'UTF-8'
  INFO - Output to 1_copy.bbl

running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

running xelatex - 3
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

用 tinytex 是一样的效果

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

generating bibliography
  INFO - This is Biber 2.20
  INFO - Logfile is '1_copy.blg'
  INFO - Reading '1_copy.bcf'
  INFO - Found 3 citekeys in bib section 0
  INFO - Processing section 0
  INFO - Looking for bibtex file 'references.bib' for section 0
  INFO - LaTeX decoding ...
  INFO - Found BibTeX data source 'references.bib'
  INFO - Overriding locale 'chinese-hans' defaults 'variable = shifted' with 'variable = non-ignorable'
  INFO - Overriding locale 'chinese-hans' defaults 'normalization = NFD' with 'normalization = prenormalized'
  INFO - Sorting list 'none/global//global/global/global' of type 'entry' with template 'none' and locale 'chinese-hans'
  INFO - No sort tailoring available for locale 'chinese-hans'
  INFO - Writing '1_copy.bbl' with encoding 'UTF-8'
  INFO - Output to 1_copy.bbl

running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

running xelatex - 3
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

Output created: 1_copy.pdf

image

jchliao commented 1 month ago

生成 tex 是这样的

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  a4paper,
]{article}

\usepackage{amsmath,amssymb}
\usepackage{setspace}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else  
    % xetex/luatex font selection
  \setmonofont[]{Consolas}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage{xcolor}
\usepackage[top=1in,left=1.25in,heightrounded]{geometry}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{5}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother

\usepackage{ctex}
\usepackage{amsthm,mathrsfs}
\usepackage{arydshln}
\newcommand{\n}{\\}
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
  \renewcommand*\contentsname{目录}
\else
  \newcommand\contentsname{目录}
\fi
\ifdefined\listfigurename
  \renewcommand*\listfigurename{图索引}
\else
  \newcommand\listfigurename{图索引}
\fi
\ifdefined\listtablename
  \renewcommand*\listtablename{表索引}
\else
  \newcommand\listtablename{表索引}
\fi
\ifdefined\figurename
  \renewcommand*\figurename{图}
\else
  \newcommand\figurename{图}
\fi
\ifdefined\tablename
  \renewcommand*\tablename{表}
\else
  \newcommand\tablename{表}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{列表}
\newcommand*\listoflistings{\listof{codelisting}{列表索引}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\makeatother
\makeatletter
\@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}{}
\makeatother
\makeatletter
\@ifundefined{codebgcolor}{\definecolor{codebgcolor}{HTML}{f1f3f5}}{}
\makeatother
\makeatletter
\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[sharp corners, boxrule=0pt, colback={codebgcolor}, frame hidden, breakable, enhanced]}{\end{tcolorbox}}\fi
\makeatother
\ifLuaTeX
\usepackage[bidi=basic]{babel}
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{chinese-hans}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\usepackage[style=gb7714-2015,backend = biber]{biblatex}
\addbibresource{references.bib}
\usepackage{bookmark}

\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
  pdflang={zh-Hans},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\author{}
\date{2024-05-23}

\begin{document}

\renewcommand*\contentsname{目录}
{
\setcounter{tocdepth}{3}
\tableofcontents
}
\setstretch{1.5}
\newpage{}

\section{问题背景}\label{ux95eeux9898ux80ccux666f}

文献\autocite{孙国强2021基于双层}。文献\autocite{符杨2022基于主从博弈的微电网群多阶段鲁棒优化规划}。文献\autocite{saravanan2013solution}。

\newpage{}

\printbibliography[title=参考文献]

\end{document}
hushidong commented 1 month ago

是不是你的biblatex-gb7714-2015比较老,重新更新或者安装一下,我看不出来到底问题出在哪了,只能后面我自己装个qurato来试一下。

前面 TomBener @TomBener 好像也用qurato,不知道有没有遇到相同的问题?

TomBener commented 1 month ago

这个问题应该是你在 _quarto.yml 中设置 lang: zh-Hans 导致的,加上这个选项之后,通过 Pandoc 生成的 LaTeX 会多出这几行设置语言的代码:

\ifLuaTeX
\usepackage[bidi=basic]{babel}
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{chinese-hans}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}

不确定是不是这几行代码对 biblatex-gb7714-2015 判断中文造成了影响。

个人建议,在使用 Pandoc 或 Quarto 时,尽量不要设置 lang 为中文,因为可能会出现意料之外的问题,保持默认的 en-US 就好,不论是 LaTeX 还是 DOCX 都是如此。对于 显示为 andotherscn 的问题,去掉 lang: zh-Hans 就可以解决。如果有中文本地化的需求,通过引入 ctex 就可以解决。

hushidong commented 1 month ago

感谢,这个解释很清楚了。

jchliao commented 1 month ago

谢谢你们,确实是这个问题

jchliao commented 1 month ago

单独找到语言配置文件后设置,可以在支持中文同时避免了生成有冲突的代码。

language: _language-zh.yml

\autociteinline 的时候有中括号,其他模式都没有。需要怎么设置才能有。 想不到特别好的解决方式了,现在用inline的方式,上标单独使用^ ^设置。

hushidong commented 1 month ago

autocite命令本来设计的就跟autocite选项相关,默认选项是inline,所以\autocite起始就是parencite。 而设置autocite=plain时,\autocite 就等于\cite, 设置为=footnote时,\autocite就是\footcite 设置为=superscript时,autocite 就是 \supercite

所以当设置autocite为不同选项时,要修改不同的格式就要修改对应的命令。

TomBener commented 1 month ago

\autociteinline 的时候有中括号,其他模式都没有。需要怎么设置才能有。 想不到特别好的解决方式了,现在用inline的方式,上标单独使用^ ^设置。

可以参考这个 issue 中提供的 workaround: https://github.com/jgm/pandoc/issues/3811

jchliao commented 1 month ago

好的,谢谢。已经达到我想要的样子了。目前来看,我只能用 quarto 写一下课程作业。对格式要求再高一点,我得特别头大了。

TomBener commented 1 month ago

Pandoc/Quarto 写中文论文确实需要很多调整,不过还是可以胜任中文毕业论文这种格式刁钻的要求的。我最近就在用 Quarto 写论文,通过自定义模板和 Lua filters,目前已解决了绝大部分问题,基本上可以实现直接生成排版完美的 DOCX/HTML/PDF 文件,后面我有时间了来分享一下。

jchliao commented 1 month ago

autocite = plain应该是要设置一下,不设置默认不太对。 尝试了直接使用 @entrykey 语法生成了 \textcite 然后直接换掉他。已经比较完美了

    include-in-header:
      text: |
        \usepackage{ctex}
        \usepackage{amsthm,mathrsfs}
        \usepackage{arydshln}
        \newcommand{\n}{\\}
    include-before-body:
      text: |
        \renewcommand{\textcite}{\parencite}
    cite-method: biblatex
    biblio-style: gb7714-2015
    biblatexoptions:
        - autocite = plain
TomBener commented 1 month ago

@jchliao 我的 Quarto 项目开源了,欢迎使用,目前还很不完善,特别是使用说明,欢迎提交 Issue 和 PR:https://github.com/TomBener/quarto-cn-tools