Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dplR::latexify to translate names to latex #109

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Conversation

mwmclean
Copy link
Collaborator

* tools::encoded_text_to_latex(text, UTF-8) can fail when text contains
Japanese characters, replacing valid text with questions marks
* Add escape hatch to return origin/unformatted/unescaped text if this
occurs
* Closes #106
* Add argument encoded.names.to.latex to toBibTeX and toBibLaTeX to
toggle whether tools::encoded_text_to_latex is called on name list fields
* Closes #105
* See toBibtex.person, braces seem necessary if no family name is detected
* Addresses #106
* Switch from tools::encoded_text_to_latex to dplR::latexify in
toBiblatex and toBibtex to fix translation of accented i characters
to latex
* Fixes #102, #106
@kijinosu
Copy link

Writing BibLatex to file then reading it gets errors.

This is with #109.

bib <- c(BibEntry(bibtype = "article", 
		key = "shiotsuki2011kasai", 
		title = "葛西賢太著,『現代瞑想論-変性意識がひらく世界-』",
		author = "塩亮子 and 葛西賢太", 
		journal = "宗教と社会",
		volume = 17,
		pages = "67--69",
		year = 2011, 
		publisher = "「宗教と社会」学会"),
		BibEntry(bibtype = "article", 
		key = "hiromitsu2022altered", 
		title = "意識状態の変容と脳内ネットワーク",
		author = "弘光健太郎 and ヒロミツケンタロウ", 
		journal = "鶴見大学仏教文化研究所紀要",
		volume = 27,
		pages = "53--66",
		year = 2022, 
		publisher = "鶴見大学"),
		BibEntry(bibtype = "article",
		key = "galante2024altered",
  		title="Altered states of consciousness caused by a mindfulness-based programme up to a year later: Results from a randomised controlled trial",
  		author="Galante, Julieta and Jesús Montero-Marín and Maris Vainre and Géraldine Dufour and Javier García-Campayo and Peter B. Jones",
  		journal="Plos one",
  		volume=19,
 		number=7,
  		pages="e0305928",
  		year=2024,
  		publisher="Public Library of Science San Francisco, CA USA")
		)

tmpfile <- tempfile(pattern = "bib109", tmpdir = tempdir(), fileext = ".bib")
WriteBib(bib, file=tmpfile, biblatex = TRUE)
bib109 <- ReadBib(tmpfile)

Results:

Ignoring entry ‘shiotsuki2011kasai’ (line1) because: 
        The name list field author cannot be parsed

Ignoring entry ‘hiromitsu2022altered’ (line11) because: 
        The name list field author cannot be parsed

警告メッセージ:
1: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
  unable to translate '塩亮子\<ff>' to a wide string
2: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
  input string 1 is invalid
3: grepl("^[[:space:]]*$", x) で:
  unable to translate '塩亮子\<ff>' to a wide string
4: grepl("^[[:space:]]*$", x) で: input string 1 is invalid
5: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
  unable to translate '弘光健太郎\<ff>' to a wide string
6: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
  input string 1 is invalid
7: grepl("^[[:space:]]*$", x) で:
  unable to translate '弘光健太郎\<ff>' to a wide string
8: grepl("^[[:space:]]*$", x) で: input string 1 is invalid

Signed-off-by: Mathew W. McLean <[email protected]>
Signed-off-by: Mathew W. McLean <[email protected]>
* When use.metadata is FALSE, pdfinfo will now still be called to determine
number of pages in the document
* This avoids a message from pdftotext in the case of 1-page PDFs

Signed-off-by: Mathew W. McLean <[email protected]>
Signed-off-by: Mathew W. McLean <[email protected]>
Signed-off-by: Mathew W. McLean <[email protected]>
@kijinosu
Copy link

kijinosu commented Oct 2, 2024

Here is an example from biblatexExamples.bib using #109:

examplepath <- file.path(system.file(package="RefManageR"),"Bib","biblatexExamples.bib")
bibexamples <- ReadBib(examplepath)

iliad <- toBiblatex(bibexamples["iliad"])
writeLines(iliad)
# @Book{iliad,
#   author = {\{Homer\}},
#   title = {Die Ilias},
#   date = {2004},
#   translator = {Wolfgang Schadewaldt},
#   introduction = {Joachim Latacz},
#   edition = {3},
#   publisher = {Artemis \& Winkler},
#   location = {D{\"u}sseldorf and Z{\"u}rich},
#   langid = {german},
#   sorttitle = {Ilias},
#   indextitle = {Ilias, Die},
#   shorttitle = {Ilias},
#   annotation = {A German translation of the \emph{Iliad}. Note the
#                   \texttt{translator} and \texttt{introduction} fields and the
#                   format of the \texttt{location} field in the database
#                   file. Also note the \texttt{sorttitle} and \texttt{indextitle}
#                   fields},
# }
tmpfile <- tempfile(pattern = "bib109", tmpdir = tempdir(), fileext = ".bib")
WriteBib(bibexamples["iliad"], file=tmpfile, biblatex = TRUE)
bib109 <- ReadBib(tmpfile)
# Ignoring entry ‘iliad’ (line1) because: 
#         The name list field author cannot be parsed
# 
# 警告メッセージ:
# 1: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
#   unable to translate 'Homer\<ff>' to a wide string
# 2: grepl("\\\\[[:punct:]]", x, useBytes = FALSE) で:
#   input string 1 is invalid
# 3: grepl("^[[:space:]]*$", x) で:
#   unable to translate 'Homer\<ff>' to a wide string
# 4: grepl("^[[:space:]]*$", x) で: input string 1 is invalid

@kijinosu
Copy link

kijinosu commented Oct 2, 2024

Note that this affects corporate authors enclosed in braces.

@book{CUDA, 
   author = {{NVIDIA Corporation}}, 
   title = {NVIDIA CUDA Compute Unified Device Architecture Programming Guide}, 
   publisher = {NVIDIA Corporation}, 
   year = {2007}
}

https://tex.stackexchange.com/questions/10808/using-a-corporate-author-in-the-author-field-of-a-bibliographic-entry-spell

* dplR::latexify escapes braces and adds tildes for whitespace
when this is not desirable for biblatex/bibtex
* Hence include modified copy of latexify in the package and add
dplR maintainer as contributor in DESCRIPTION
@mwmclean
Copy link
Collaborator Author

mwmclean commented Oct 2, 2024

@kijinosu thanks for your report. Addressed by my last commit if you'd like to pull and reinstall.

@kijinosu
Copy link

kijinosu commented Oct 3, 2024

Note that this affects corporate authors enclosed in braces.

@book{CUDA, 
   author = {{NVIDIA Corporation}}, 
   title = {NVIDIA CUDA Compute Unified Device Architecture Programming Guide}, 
   publisher = {NVIDIA Corporation}, 
   year = {2007}
}

https://tex.stackexchange.com/questions/10808/using-a-corporate-author-in-the-author-field-of-a-bibliographic-entry-spell

@kijinosu thanks for your report. Addressed by my last commit if you'd like to pull and reinstall.

This works very nicely. Thank you for working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RefManageR::ReadBib and RefManageR::WriteBib changes Ois{\'i}n to Ois{\a'\i}n
2 participants