【问题标题】:reading latex accents of .bib in R在 R 中阅读 .bib 的乳胶口音
【发布时间】:2020-06-15 14:59:08
【问题描述】:

当我导出带有以乳胶编码的重音符号的 .bib 引用时(例如,它们是从 mendeley 导出的),它们看起来不像预期的那样可以在 R 中进行进一步的独立处理。

我的文件.bib:

@misc{Llorens1980,
abstract = {Aunque el reactor de fusi{\'{o}}n termonuclear constituye la esperanza m{\'{a}}s s{\'{o}}lida de obtenci{\'{o}}n de energ{\'{i}}a a gran escala, los problemas f{\'{i}}sicos y tecnol{\'{o}}gicos que el mismo plantea son muchos y dif{\'{i}}ciles.},
author = {Llorens, Mart{\'{i}}n and Menzell, Alfred and Villarrubia, Miguel},
booktitle = {Investigaci{\'{o}}n y Ciencia (Scientific American)},
keywords = {INGENIER{\'{I}}A NUCLEAR},
number = {51},
pages = {1--5},
title = {{F{\'{i}}sica y tecnolog{\'{i}}a del reactor de fusi{\'{o}}n}},
volume = {DICIEMBRE},
year = {1980}
}

在 R 中:

testbibR <- RefManageR::ReadBib("myfile.bib")
testbibR$author
[1] "Mart\\'in Llorens"  "Alfred Menzell"     "Miguel Villarrubia"
testbibR$title
[1] "{F{\\'{i}}sica y tecnolog{\\'{i}}a del reactor de fusi{\\'{o}}n}"

btex<-bibtex::read.bib("myfile.bib")
btex$author
[1] "Mart\\'in Llorens"  "Alfred Menzell"     "Miguel Villarrubia"
btex$title
[1] "{F{\\'{i}}sica y tecnolog{\\'{i}}a del reactor de fusi{\\'{o}}n}"

testbib <- bib2df::bib2df("myfile.bib")
testbib$AUTHOR[[1]]
[1] "Llorens, Mart{\\'{i}}n" "Menzell, Alfred"        "Villarrubia, Miguel"   
testbib$TITLE
[1] "F{\\'{i}}sica y tecnolog{\\'{i}}a del reactor de fusi{\\'{o}}n" 

我想知道我是否可以在那些地方看到Martín

相关帖子:https://github.com/ropensci/bib2df/issues/35

顺便说一句,在导入/导出这些围兜时,包似乎以(其他)乳胶格式重写,作者字段(Mart\'in)。只有bib2df 将所有字段写入原始字段,见上文。

RefManageR::WriteBib(testbibR,"refmanager.bib")

bibtex::write.bib(btex,"bibtex.bib")

bib2df::df2bib(testbib,"bib2df")

【问题讨论】:

  • 我不熟悉任何用于 R 的 TeX 到 Unicode 转换器。您可能只需要手动替换您关心的 unicode 字符。

标签: r latex bibtex


【解决方案1】:

这是从 .bib 中删除一些乳胶重音符号的解决方法。

当我在这个post' answer 中基于这个答案时,第一部分是在 python 中。

python:字典到 .csv

latexAccents = [
    [ u"Í", "{\\'{I}}"],
    [ u"í", "{\\'{i}}"],
    [ u"á", "{\\'{a}}"],
    [ u"é", "{\\'{e}}"],
    [ u"ó", "{\\'{o}}"],
    [ u"ú", "{\\'{u}}"],
    ]

import pandas

mydf = pandas.DataFrame(latexAccents)
newname = "dictaccent.csv"
mydf.to_csv(newname, index =False)

R:替换 .bib 中的乳胶

dictaccent <- read.csv("dictaccent.csv")
bibLines   <- readLines("myfile.bib")

library(stringi)

for (i in 1:nrow(dictaccent)){
    for (j in 1:length(bibLines)) {
        bibLines[j]<-stri_replace_all_fixed(bibLines[j], dictaccent$X1[i], dictaccent$X0[i])
    }
}

writeLines(bibLines,"noLatex.bib")

commented in other post

【讨论】:

    猜你喜欢
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多