citation-bibliography-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Citation & Bibliography Generator

引文与参考文献生成器

Generate properly formatted citations and bibliographies in multiple academic and professional styles. Supports manual entry, structured data import, and automatic metadata lookup via DOI/ISBN.
生成符合多种学术和专业格式规范的引文和参考文献目录,支持手动输入、结构化数据导入,以及通过DOI/ISBN自动查询元数据。

Quick Start

快速开始

python
from scripts.citation_generator import CitationGenerator
python
from scripts.citation_generator import CitationGenerator

Create generator with desired style

Create generator with desired style

gen = CitationGenerator(style='apa')
gen = CitationGenerator(style='apa')

Cite a book

Cite a book

citation = gen.cite_book( authors=["Smith, John", "Doe, Jane"], title="Research Methods in Social Science", year=2020, publisher="Academic Press", city="New York" ) print(citation)
citation = gen.cite_book( authors=["Smith, John", "Doe, Jane"], title="Research Methods in Social Science", year=2020, publisher="Academic Press", city="New York" ) print(citation)

Output: Smith, J., & Doe, J. (2020). Research methods in social science. Academic Press.

Output: Smith, J., & Doe, J. (2020). Research methods in social science. Academic Press.

Build bibliography

Build bibliography

gen.add_to_bibliography(citation) bibliography = gen.generate_bibliography() print(bibliography)
undefined
gen.add_to_bibliography(citation) bibliography = gen.generate_bibliography() print(bibliography)
undefined

Supported Citation Styles

支持的引文格式

  • APA (American Psychological Association) - 7th Edition
  • MLA (Modern Language Association) - 9th Edition
  • Chicago (Chicago Manual of Style) - 17th Edition
  • IEEE (Institute of Electrical and Electronics Engineers)
  • Harvard (Harvard referencing style)
  • APA (美国心理学会) - 第7版
  • MLA (现代语言协会) - 第9版
  • Chicago (芝加哥手册格式) - 第17版
  • IEEE (电气和电子工程师协会)
  • Harvard (哈佛参考文献格式)

Features

功能特性

1. Manual Citation Creation

1. 手动创建引文

Format citations by source type:
  • Books - Monographs, edited volumes, editions
  • Journal Articles - Peer-reviewed articles with DOI
  • Websites - Online sources with access dates
  • Conference Papers - Proceedings and presentations
按来源类型格式化引文:
  • 图书 - 专著、编辑文集、不同版本图书
  • 期刊文章 - 带有DOI的同行评审文章
  • 网站 - 带有访问日期的线上资源
  • 会议论文 - 会议论文集和演示文稿

2. Automatic Metadata Lookup

2. 自动元数据查询

  • DOI Lookup - Fetch article metadata from CrossRef API
  • ISBN Lookup - Retrieve book information (when available)
  • Auto-detect source type and format accordingly
  • DOI 查询 - 从CrossRef API获取文章元数据
  • ISBN 查询 - 检索图书信息(如有可用数据)
  • 自动识别来源类型并对应格式化

3. Bibliography Management

3. 参考文献管理

  • Add multiple citations
  • Auto-sort by author, year, or title
  • Duplicate detection and removal
  • Export to plain text or BibTeX
  • 添加多条引文
  • 按作者、年份或标题自动排序
  • 重复项检测与移除
  • 导出为纯文本或BibTeX格式

4. In-Text Citations

4. 文内引文

Generate parenthetical or narrative in-text citations:
  • Parenthetical:
    (Smith, 2020, p. 45)
  • Narrative:
    Smith (2020) argues that...
  • Multiple authors with et al. handling
生成括号式或叙述式文内引文:
  • 括号式:
    (Smith, 2020, p. 45)
  • 叙述式:
    Smith (2020) argues that...
  • 多作者场景下自动处理et al.规则

5. Batch Processing

5. 批量处理

Import citations from CSV files with structured data and generate complete bibliographies.
从CSV文件导入结构化引文数据,生成完整的参考文献目录。

API Reference

API 参考

CitationGenerator

CitationGenerator

Initialization:
python
gen = CitationGenerator(style='apa')
Parameters:
  • style
    (str): Citation style - 'apa', 'mla', 'chicago', 'ieee', or 'harvard'
初始化:
python
gen = CitationGenerator(style='apa')
参数:
  • style
    (str): 引文格式 - 'apa', 'mla', 'chicago', 'ieee', 或 'harvard'

Citation Methods

引文生成方法

cite_book()

cite_book()

python
citation = gen.cite_book(
    authors=["Last, First", "Last, First"],
    title="Book Title",
    year=2020,
    publisher="Publisher Name",
    city="City",           # Optional
    edition="3rd ed.",     # Optional
    isbn="978-0-123456-78-9"  # Optional
)
Returns: Formatted citation string
python
citation = gen.cite_book(
    authors=["Last, First", "Last, First"],
    title="Book Title",
    year=2020,
    publisher="Publisher Name",
    city="City",           # Optional
    edition="3rd ed.",     # Optional
    isbn="978-0-123456-78-9"  # Optional
)
返回: 格式化后的引文字符串

cite_article()

cite_article()

python
citation = gen.cite_article(
    authors=["Last, First"],
    title="Article Title",
    journal="Journal Name",
    year=2020,
    volume=10,          # Optional
    issue=2,            # Optional
    pages="45-67",      # Optional
    doi="10.1234/example"  # Optional
)
Returns: Formatted citation string
python
citation = gen.cite_article(
    authors=["Last, First"],
    title="Article Title",
    journal="Journal Name",
    year=2020,
    volume=10,          # Optional
    issue=2,            # Optional
    pages="45-67",      # Optional
    doi="10.1234/example"  # Optional
)
返回: 格式化后的引文字符串

cite_website()

cite_website()

python
citation = gen.cite_website(
    authors=["Last, First"],  # Can be empty list
    title="Page Title",
    url="https://example.com",
    access_date="2024-01-15",
    publish_date="2023-12-01"  # Optional
)
Returns: Formatted citation string
python
citation = gen.cite_website(
    authors=["Last, First"],  # Can be empty list
    title="Page Title",
    url="https://example.com",
    access_date="2024-01-15",
    publish_date="2023-12-01"  # Optional
)
返回: 格式化后的引文字符串

cite_from_doi()

cite_from_doi()

python
citation = gen.cite_from_doi(doi="10.1234/example")
Looks up article metadata from CrossRef API and generates formatted citation.
Returns: Formatted citation string
python
citation = gen.cite_from_doi(doi="10.1234/example")
从CrossRef API查询文章元数据并生成格式化引文。
返回: 格式化后的引文字符串

Bibliography Management

参考文献管理

add_to_bibliography()

add_to_bibliography()

python
gen.add_to_bibliography(citation)
Add a citation to the bibliography list.
python
gen.add_to_bibliography(citation)
将一条引文添加到参考文献列表中。

generate_bibliography()

generate_bibliography()

python
bibliography = gen.generate_bibliography(
    sort_by='author',      # 'author', 'year', or 'title'
    deduplicate=True       # Remove duplicate entries
)
Returns: Formatted bibliography string with hanging indent
python
bibliography = gen.generate_bibliography(
    sort_by='author',      # 'author', 'year', or 'title'
    deduplicate=True       # Remove duplicate entries
)
返回: 带有悬挂缩进的格式化参考文献字符串

export_bibtex()

export_bibtex()

python
gen.export_bibtex(output_path='references.bib')
Export bibliography as BibTeX format for LaTeX documents.
python
gen.export_bibtex(output_path='references.bib')
将参考文献导出为BibTeX格式,用于LaTeX文档。

In-Text Citations

文内引文

in_text_citation()

in_text_citation()

python
citation = gen.in_text_citation(
    authors=["Smith, J."],
    year=2020,
    page="45",          # Optional
    narrative=False     # True for narrative style
)
Returns:
  • Parenthetical:
    (Smith, 2020, p. 45)
  • Narrative:
    Smith (2020)
python
citation = gen.in_text_citation(
    authors=["Smith, J."],
    year=2020,
    page="45",          # Optional
    narrative=False     # True for narrative style
)
返回:
  • 括号式:
    (Smith, 2020, p. 45)
  • 叙述式:
    Smith (2020)

Batch Processing

批量处理

import_from_csv()

import_from_csv()

python
citations = gen.import_from_csv(csv_path='citations.csv')
Import multiple citations from CSV file.
CSV Format:
csv
type,authors,title,year,journal,publisher,doi,isbn,url,access_date
article,"Smith, J.|Doe, A.",Research Methods,2020,Journal of Science,,10.1234/example,,,
book,"Johnson, M.",Data Analysis,2019,,Academic Press,,978-0-123456-78-9,,
website,,"Web Page Title",2024,,,,,https://example.com,2024-01-15
Note: Separate multiple authors with
|
pipe character
Returns: List of formatted citation strings
python
citations = gen.import_from_csv(csv_path='citations.csv')
从CSV文件导入多条引文。
CSV 格式:
csv
type,authors,title,year,journal,publisher,doi,isbn,url,access_date
article,"Smith, J.|Doe, A.",Research Methods,2020,Journal of Science,,10.1234/example,,,
book,"Johnson, M.",Data Analysis,2019,,Academic Press,,978-0-123456-78-9,,
website,,"Web Page Title",2024,,,,,https://example.com,2024-01-15
注意: 多个作者之间用
|
竖线分隔
返回: 格式化后的引文字符串列表

CLI Usage

CLI 用法

Single Citation

单条引文生成

Book:
bash
python scripts/citation_generator.py book \
    --authors "Smith, J." "Doe, A." \
    --title "Research Methods" \
    --year 2020 \
    --publisher "Academic Press" \
    --city "New York" \
    --style apa
Article:
bash
python scripts/citation_generator.py article \
    --authors "Smith, J." \
    --title "Study Title" \
    --journal "Journal Name" \
    --year 2020 \
    --volume 10 \
    --issue 2 \
    --pages "45-67" \
    --doi "10.1234/example" \
    --style mla
Website:
bash
python scripts/citation_generator.py website \
    --title "Page Title" \
    --url "https://example.com" \
    --access-date "2024-01-15" \
    --style chicago
图书:
bash
python scripts/citation_generator.py book \
    --authors "Smith, J." "Doe, A." \
    --title "Research Methods" \
    --year 2020 \
    --publisher "Academic Press" \
    --city "New York" \
    --style apa
文章:
bash
python scripts/citation_generator.py article \
    --authors "Smith, J." \
    --title "Study Title" \
    --journal "Journal Name" \
    --year 2020 \
    --volume 10 \
    --issue 2 \
    --pages "45-67" \
    --doi "10.1234/example" \
    --style mla
网站:
bash
python scripts/citation_generator.py website \
    --title "Page Title" \
    --url "https://example.com" \
    --access-date "2024-01-15" \
    --style chicago

DOI Lookup

DOI 查询

bash
python scripts/citation_generator.py doi \
    --doi "10.1234/example" \
    --style apa
bash
python scripts/citation_generator.py doi \
    --doi "10.1234/example" \
    --style apa

Batch Processing

批量处理

bash
python scripts/citation_generator.py batch \
    --input citations.csv \
    --style harvard \
    --output bibliography.txt \
    --sort author
bash
python scripts/citation_generator.py batch \
    --input citations.csv \
    --style harvard \
    --output bibliography.txt \
    --sort author

BibTeX Export

BibTeX 导出

bash
python scripts/citation_generator.py batch \
    --input citations.csv \
    --format bibtex \
    --output references.bib
bash
python scripts/citation_generator.py batch \
    --input citations.csv \
    --format bibtex \
    --output references.bib

CLI Arguments

CLI 参数

ArgumentDescriptionDefault
--style
,
-s
Citation style (apa/mla/chicago/ieee/harvard)apa
--authors
,
-a
Author names (multiple allowed)-
--title
,
-t
Title of work-
--year
,
-y
Publication year-
--input
,
-i
Input CSV file (batch mode)-
--output
,
-o
Output file pathstdout
--format
,
-f
Output format (text/bibtex)text
--sort
Sort bibliography by (author/year/title)author
参数说明默认值
--style
,
-s
引文格式 (apa/mla/chicago/ieee/harvard)apa
--authors
,
-a
作者姓名(可传入多个)-
--title
,
-t
作品标题-
--year
,
-y
出版年份-
--input
,
-i
输入CSV文件(批量模式)-
--output
,
-o
输出文件路径标准输出
--format
,
-f
输出格式 (text/bibtex)text
--sort
参考文献排序依据 (author/year/title)author

Examples

示例

Example 1: APA Book Citation

示例1: APA格式图书引文

python
gen = CitationGenerator(style='apa')
citation = gen.cite_book(
    authors=["Doe, Jane", "Smith, John"],
    title="The Art of Research",
    year=2021,
    publisher="University Press",
    edition="2nd ed."
)
print(citation)
python
gen = CitationGenerator(style='apa')
citation = gen.cite_book(
    authors=["Doe, Jane", "Smith, John"],
    title="The Art of Research",
    year=2021,
    publisher="University Press",
    edition="2nd ed."
)
print(citation)

Doe, J., & Smith, J. (2021). The art of research (2nd ed.). University Press.

Doe, J., & Smith, J. (2021). The art of research (2nd ed.). University Press.

undefined
undefined

Example 2: MLA Article Citation

示例2: MLA格式期刊文章引文

python
gen = CitationGenerator(style='mla')
citation = gen.cite_article(
    authors=["Johnson, Mary"],
    title="Digital Humanities in the 21st Century",
    journal="Modern Research Quarterly",
    year=2022,
    volume=15,
    issue=3,
    pages="112-145",
    doi="10.5678/mrq.2022.15.3"
)
print(citation)
python
gen = CitationGenerator(style='mla')
citation = gen.cite_article(
    authors=["Johnson, Mary"],
    title="Digital Humanities in the 21st Century",
    journal="Modern Research Quarterly",
    year=2022,
    volume=15,
    issue=3,
    pages="112-145",
    doi="10.5678/mrq.2022.15.3"
)
print(citation)

Johnson, Mary. "Digital Humanities in the 21st Century." Modern Research Quarterly, vol. 15, no. 3, 2022, pp. 112-145. DOI: 10.5678/mrq.2022.15.3.

Johnson, Mary. "Digital Humanities in the 21st Century." Modern Research Quarterly, vol. 15, no. 3, 2022, pp. 112-145. DOI: 10.5678/mrq.2022.15.3.

undefined
undefined

Example 3: Chicago Website Citation

示例3: Chicago格式网站引文

python
gen = CitationGenerator(style='chicago')
citation = gen.cite_website(
    authors=["Brown, Robert"],
    title="Understanding Machine Learning",
    url="https://ml-guide.example.com",
    access_date="2024-01-20",
    publish_date="2023-11-15"
)
print(citation)
python
gen = CitationGenerator(style='chicago')
citation = gen.cite_website(
    authors=["Brown, Robert"],
    title="Understanding Machine Learning",
    url="https://ml-guide.example.com",
    access_date="2024-01-20",
    publish_date="2023-11-15"
)
print(citation)

Brown, Robert. "Understanding Machine Learning." Last modified November 15, 2023. Accessed January 20, 2024. https://ml-guide.example.com.

Brown, Robert. "Understanding Machine Learning." Last modified November 15, 2023. Accessed January 20, 2024. https://ml-guide.example.com.

undefined
undefined

Example 4: Building a Bibliography

示例4: 生成参考文献目录

python
gen = CitationGenerator(style='apa')
python
gen = CitationGenerator(style='apa')

Add multiple citations

Add multiple citations

gen.add_to_bibliography(gen.cite_book( authors=["Smith, A."], title="First Book", year=2020, publisher="Press A" ))
gen.add_to_bibliography(gen.cite_article( authors=["Jones, B."], title="Research Article", journal="Journal X", year=2021 ))
gen.add_to_bibliography(gen.cite_book( authors=["Smith, A."], title="First Book", year=2020, publisher="Press A" ))
gen.add_to_bibliography(gen.cite_article( authors=["Jones, B."], title="Research Article", journal="Journal X", year=2021 ))

Generate formatted bibliography

Generate formatted bibliography

bibliography = gen.generate_bibliography(sort_by='author') print(bibliography)
undefined
bibliography = gen.generate_bibliography(sort_by='author') print(bibliography)
undefined

Example 5: DOI Lookup

示例5: DOI查询生成引文

python
gen = CitationGenerator(style='ieee')
citation = gen.cite_from_doi(doi="10.1109/ACCESS.2019.2947014")
print(citation)
python
gen = CitationGenerator(style='ieee')
citation = gen.cite_from_doi(doi="10.1109/ACCESS.2019.2947014")
print(citation)

Auto-fetches metadata and formats in IEEE style

Auto-fetches metadata and formats in IEEE style

undefined
undefined

Example 6: Batch Processing from CSV

示例6: 从CSV批量处理

python
gen = CitationGenerator(style='harvard')
citations = gen.import_from_csv('my_references.csv')
python
gen = CitationGenerator(style='harvard')
citations = gen.import_from_csv('my_references.csv')

Add all to bibliography

Add all to bibliography

for citation in citations: gen.add_to_bibliography(citation)
for citation in citations: gen.add_to_bibliography(citation)

Generate and export

Generate and export

gen.export_bibtex('references.bib')
undefined
gen.export_bibtex('references.bib')
undefined

Dependencies

依赖

pandas>=2.0.0
requests>=2.31.0
Install dependencies:
bash
pip install -r scripts/requirements.txt
pandas>=2.0.0
requests>=2.31.0
安装依赖:
bash
pip install -r scripts/requirements.txt

Limitations

局限性

  • API Availability: DOI/ISBN lookups require internet connection and depend on third-party APIs (CrossRef)
  • API Rate Limits: CrossRef API has rate limits; implement delays for batch lookups
  • Style Variations: Some citation styles have discipline-specific variations not fully covered
  • Special Characters: Unicode support for accents and special characters may vary by output format
  • Edition Numbers: Different styles format editions differently (ordinal vs text)
  • Author Name Formats: Input should be "Last, First" format; parsing other formats may be inconsistent
  • Multiple Authors: Et al. rules vary by style (APA: 3+, MLA: 3+, Chicago: 4+)
  • Online-First Articles: Articles published online before print may have partial metadata
  • Non-English Sources: Some citation styles have specific rules for non-English sources that may not be fully implemented
  • API 可用性: DOI/ISBN查询需要联网,依赖第三方API(CrossRef)
  • API 速率限制: CrossRef API有访问速率限制,批量查询时需要添加延迟
  • 格式变体: 部分引文格式存在学科特有的变体,未被完全覆盖
  • 特殊字符: 重音符号等特殊字符的Unicode支持可能因输出格式不同存在差异
  • 版本号: 不同格式对版本号的展示方式不同(序数词/文字表述)
  • 作者姓名格式: 输入需遵循「姓, 名」格式,解析其他格式可能存在不一致
  • 多作者处理: Et al.规则因格式而异(APA: 3名及以上作者,MLA: 3名及以上,Chicago:4名及以上)
  • 在线优先文章: 先上线后印刷的文章可能元数据不完整
  • 非英文来源: 部分引文格式对非英文来源有特殊规则,未被完全实现

Citation Style Guidelines

引文格式规范

APA (American Psychological Association)

APA (美国心理学会)

  • Author-date system
  • Ampersand (&) before last author
  • Title case for book titles, sentence case for article titles
  • DOI as URL: https://doi.org/10.xxxx
  • 作者-年份体系
  • 最后一位作者前加&符号
  • 图书标题用标题大小写,文章标题用句子大小写
  • DOI作为URL展示: https://doi.org/10.xxxx

MLA (Modern Language Association)

MLA (现代语言协会)

  • Author-page system
  • "And" before last author
  • Title case for all titles
  • Container concept (journal is container for article)
  • 作者-页码体系
  • 最后一位作者前加"And"
  • 所有标题用标题大小写
  • 容器概念(期刊是文章的容器)

Chicago (Chicago Manual of Style)

Chicago (芝加哥手册格式)

  • Notes and bibliography system
  • "And" before last author
  • Title case for titles
  • Access dates for websites
  • 注释与参考文献体系
  • 最后一位作者前加"And"
  • 标题用标题大小写
  • 网站资源需标注访问日期

IEEE (Institute of Electrical and Electronics Engineers)

IEEE (电气和电子工程师协会)

  • Numbered references [1], [2], etc.
  • Initials before last name
  • Quotation marks for article titles
  • Abbreviated journal names
  • 带编号的参考文献 [1], [2] 等
  • 首字母在前,姓在后
  • 文章标题加引号
  • 期刊名称用缩写

Harvard

Harvard

  • Author-date system
  • "And" before last author
  • Italic for book/journal titles
  • Available at: for URLs
  • 作者-年份体系
  • 最后一位作者前加"And"
  • 图书/期刊标题用斜体
  • URL前加"Available at:"