BibLaTeX: Làm cách nào để xóa dấu phẩy sau “school” trong mục nhập @thesis?

Aug 15 2020

Tôi muốn xóa dấu phẩy giữa trường "trường" và ngày (năm) trong mục nhập thư mục @thesis:

Đây là mã ví dụ tối thiểu của tôi:

\documentclass{minimal}

\usepackage{ngerman}
\usepackage[backend = biber, style = numeric]{biblatex}

%%%%%%%% https://tex.stackexchange.com/a/492917

\newtoggle{bbx:datemissing}

\renewbibmacro*{date}{\toggletrue{bbx:datemissing}%}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datemissing}%
  \iffieldundef{issue}{}{
    \printtext[parens]{%
    \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \togglefalse{bbx:datemissing}%
  \printdate}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

%%%%%%%%

%%% This is what I came up with
\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}{%
    \setunit*{\space}%
  }{%
    \setunit*{\addcolon\space}%
  }%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \newunit%
}

\usepackage{filecontents}
\begin{filecontents*}{lit.bib}
  @thesis {mythesis,
    author = {Me, I.},
    school = {University},
    title = {Sometitle},
    type = {Phd thesis},
    year = {123}
  }  
\end{filecontents*}

\addbibresource{lit.bib}

\begin{document}
\printbibliography
\end{document}
\nocite{*}

Tôi đã thử \renewbibmacro{institution+location+date}{...}, nhưng điều đó không hiệu quả. Tôi còn khá mới với BibLaTeX.

Suy nghĩ của tôi là numerickiểu sử dụng các loại mục nhập từ standardđó là nơi tôi đã sao chép macro và xóa tất cả các dấu phẩy. Tuy nhiên, điều đó rõ ràng đã không hiệu quả. Làm cách nào để xóa dấu phẩy này?

Trả lời

3 AlanMunn Aug 15 2020 at 22:37

Bạn có thể thêm \nopunctngay trước macro đã \newunitxác định lại của mình institution+location+date. Tôi đã thay đổi lớp tài liệu trong ví dụ của bạn thành article. Mặc dù có tên như vậy, minimallớp tài liệu không nên được sử dụng cho MWE vì trên thực tế nó quá nhỏ. Tôi cũng đã xóa filecontentsgói này, hiện là một phần của hạt nhân LaTeX.

\documentclass{article}

\usepackage{ngerman}
\usepackage[backend = biber, style = numeric]{biblatex}

\newtoggle{bbx:datemissing}

\renewbibmacro*{date}{\toggletrue{bbx:datemissing}}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datemissing}%
  \iffieldundef{issue}{}{
    \printtext[parens]{%
    \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \togglefalse{bbx:datemissing}%
  \printdate}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}
%%% This is what I came up with
\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}{%
    \setunit*{\space}%
  }{%
    \setunit*{\space}%
  }%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \nopunct\newunit%
}

\begin{filecontents*}[overwrite]{\jobname.bib}
  @thesis {mythesis,
    author = {Me, I.},
    school = {University of Somewhere},
    title = {Sometitle},
    type = {Phd thesis},
    year = {1980}
  }  
\end{filecontents*}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

2 moewe Aug 16 2020 at 10:45

Câu trả lời cho Thay đổi thứ tự của các trang và năm trong Biblatex , có mã bạn đang sử dụng, sử dụng các công cụ khá cùn để di chuyển việc datein sau đó pages. Đây có thể không phải là chính xác những gì bạn muốn hoặc cần trong mọi tình huống.

Đây là một thiết lập phức tạp hơn một chút, chỉ di chuyển ngày nếu có pages(hoặc a chapter), điều này có thể dẫn đến kết quả hoạt động tốt hơn một chút cho bạn trong một số trường hợp.

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[backend=biber, style=numeric]{biblatex}

\newtoggle{bbx:datesuppressed}

\renewbibmacro*{date}{%
  \ifboolexpr{
        test {\iffieldundef{pages}}
    and test {\iffieldundef{chapter}}}
    {\printdate}
    {\toggletrue{bbx:datesuppressed}}}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datesuppressed}%
  \iffieldundef{issue}
    {}
    {\printtext[parens]{%
       \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \iftoggle{bbx:datesuppressed}
    {\togglefalse{bbx:datesuppressed}%
     \printdate}
    {}}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}
    {\setunit*{\space}}
    {\setunit*{\addcolon\space}}%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \newunit
}

\begin{filecontents*}{\jobname.bib}
@phdthesis{mythesis,
  author = {Me, I.},
  school = {University},
  title  = {Sometitle},
  year   = {123},
}  
\end{filecontents*}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\nocite{mythesis,sigfridsson,westfahl:space}
\printbibliography
\end{document}

Như Alan đã giải thích trong phần nhận xét bên dưới câu trả lời của mình, biblatexcách xử lý dấu câu của không đồng bộ: Dấu câu được lưu trữ trong bộ đệm và chỉ được in khi cần thiết (tức là khi \print...lệnh tiếp theo thực sự in một thứ gì đó). Vì trong đoạn mã trong câu hỏi, phần \usebibmacro{date}in institution+location+datekhông thực sự in ngày tháng, nên phần \setunittrước đó cuối cùng không kiểm soát dấu chấm câu trước ngày. Ngày chỉ in bằng date:printtrong chapter+pages, lúc này khác \setunitlệnh sẽ có thêm dấu chấm câu khác nhau vào bộ đệm.

\nopunctđặt một điểm đánh dấu vĩnh viễn không in bất kỳ dấu câu nào cho đến khi nội dung / văn bản mới được in bằng \print...lệnh. Trong trường hợp này, nó giúp ngăn chặn khoảng thời gian không mong muốn. Vì \nopunctcó thể được sử dụng bên trong và bên ngoài trình theo dõi dấu câu, nên đây là một công cụ tiện dụng để điều chỉnh dấu câu, nhưng tôi thường cố gắng tránh nó và thích các giải pháp không sử dụng nó, vì nó có thể có những tác động vượt quá những gì mong muốn.