Title: | Use Interlinear Glosses in R Markdown |
---|---|
Description: | Read examples with interlinear glosses from files or from text and print them in a way compatible with both Latex and HTML outputs. |
Authors: | Mariana Montes [aut, cre] |
Maintainer: | Mariana Montes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.0 |
Built: | 2025-02-13 04:58:32 UTC |
Source: | https://github.com/montesmariana/glossr |
gloss
objectsBased on a character vectors and up to three label arguments, create an object where those arguments are attributes. These are:
source: Where the text comes from. This will be printed in the first line of the example, without word alignment.
translation: Free translation. This will be printed as the last line of the example, without word alignment and in quotation marks if so desired.
label: Named label of the example, for cross-references.
lengths: This is computed within the function, not provider, and it's the number of items identified in each gloss line.
as_gloss( ..., source = NULL, translation = NULL, label = NULL, trans_quotes = config$trans_quotes, output_format = config$output, numbering = config$numbering )
as_gloss( ..., source = NULL, translation = NULL, label = NULL, trans_quotes = config$trans_quotes, output_format = config$output, numbering = config$numbering )
... |
Lines for glossing |
source |
(Optional) Source of example |
translation |
(Optional) Free translation |
label |
(Optional) Example label |
trans_quotes |
(Optional) Quotes to surround the free translation with. |
output_format |
(Optional) Whether it will use latex, word or html format. |
numbering |
(Optional) Whether the gloss should be numbered (in Word and HTML). |
Object of class gloss
, ready to be printed based on the chosen output format,
and with a gloss_data
object as data
attribute (or, in the case of calls via
gloss_df()
, the original input asdata
).
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" ex_trans <- "An example in Spanish" my_gloss <- as_gloss(ex_sp, ex_gloss, translation = ex_trans, label="ex1") # check the gloss data attr(my_gloss, "data")
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" ex_trans <- "An example in Spanish" my_gloss <- as_gloss(ex_sp, ex_gloss, translation = ex_trans, label="ex1") # check the gloss data attr(my_gloss, "data")
Read configuration from a YAML file to provide instructions for styling and PDF- or Word-specific options.
config_from_file(filename)
config_from_file(filename)
filename |
Path to the YAML configuration file, e.g. "glossr-config.yaml". |
Invisibly, the contents of the configuration file that passed validation.
config_file <- system.file("extdata/glossr-config.yml", package="glossr") config_from_file(config_file) print_config()
config_file <- system.file("extdata/glossr-config.yml", package="glossr") config_from_file(config_file) print_config()
Latex output uses \@ref(label)
to reference examples,
whereas HTML output is based on pandoc examples, i.e. (@label)
.
`r gloss(label)`
, written inline in the text, will return the
appropriate reference based on the selected output.
gloss(label)
gloss(label)
label |
Label for reference |
Character string with label reference
gloss_data
classBased on a character vectors and up to three label arguments, create an object where those arguments are attributes. These are:
source: Where the text comes from. This will be printed in the first line of the example, without word alignment.
translation: Free translation. This will be printed as the last line of the example, without word alignment and in quotation marks if so desired.
label: Named label of the example, for cross-references.
lengths: This is computed within the function, not provider, and it's the number of items identified in each gloss line.
new_gloss_data( gloss_lines, source = NULL, translation = NULL, label = NULL, trans_quotes = config$trans_quotes )
new_gloss_data( gloss_lines, source = NULL, translation = NULL, label = NULL, trans_quotes = config$trans_quotes )
gloss_lines |
Lines for glossing, as a list |
source |
(Optional) Source of example |
translation |
(Optional) Free translation |
label |
(Optional) Example label |
trans_quotes |
(Optional) Quotes to surround the free translation with. |
This function is mostly for internal use, but may be useful for debugging or
checking the output of specific calls. Normally, it's best to use
as_gloss()
or gloss_df()
.
Note that, unlike as_gloss()
, new_gloss_data
requires a list
of gloss lines.
Object of class gloss_data
Render gloss from a dataframe
gloss_df(df, output_format = config$output, numbering = config$numbering)
gloss_df(df, output_format = config$output, numbering = config$numbering)
df |
Dataframe one row per gloss. Columns |
output_format |
(Optional) Whether it will use latex, word or html format. |
numbering |
(Optional) Whether the gloss should be numbered (in Word and HTML). |
Object of class gloss
with the original input as data
attribute.
my_gloss <- data.frame( first_line = "my first line", second_line = "my second line", translation = "Translation of my example", label = "label" ) gloss_df(my_gloss)
my_gloss <- data.frame( first_line = "my first line", second_line = "my second line", translation = "Translation of my example", label = "label" ) gloss_df(my_gloss)
This function takes a dataframe with glosses and returns another function
that takes either an id or list of ids (if use_conditionals
is FALSE
)
or a conditional statement (if TRUE
) and runs gloss_df()
on the filtered
dataframe.
gloss_factory( glosses, use_conditionals = FALSE, id_column = "label", ignore_columns = NULL, validate = TRUE )
gloss_factory( glosses, use_conditionals = FALSE, id_column = "label", ignore_columns = NULL, validate = TRUE )
glosses |
Dataframe with gloss data. |
use_conditionals |
Boolean. If |
id_column |
Name of the column with ids for filtering, if |
ignore_columns |
Optional character vector with names of columns that could
be used for filtering but should not be provided to |
validate |
Boolean. If |
A function.
If use_conditionals
is FALSE
(the default), the returned
function will take a character vector or a series of character vectors with
id's to filter. If id_column
is "label", running that function will be
the equivalent to filtering glosses
based on the values in the label
column.
If use_conditionals
is TRUE
, the returned function will take the same
conditions that a dplyr::filter()
would.
my_glosses <- dplyr::select(glosses, -language) by_label <- gloss_factory(my_glosses) by_label("heartwarming-jp") by_label("heartwarming-jp", "languid-jp") by_cond <- gloss_factory(my_glosses, use_conditional = TRUE) by_cond(stringr::str_ends(label, "jp"))
my_glosses <- dplyr::select(glosses, -language) by_label <- gloss_factory(my_glosses) by_label("heartwarming-jp") by_label("heartwarming-jp", "languid-jp") by_cond <- gloss_factory(my_glosses, use_conditional = TRUE) by_cond(stringr::str_ends(label, "jp"))
Facilitates applying the same latex formatting to different words in a row.
gloss_format_words(text, formatting)
gloss_format_words(text, formatting)
text |
Character vector of length 1. |
formatting |
Latex formatting code, e.g. |
Reformatted string
gloss_format_words("Many words to apply italics on.", "textit")
gloss_format_words("Many words to apply italics on.", "textit")
Apply tooltip to a full gloss
gloss_linetooltip(original, parsed)
gloss_linetooltip(original, parsed)
original |
Text to show in the |
parsed |
Text to show as tooltip when hovering |
List of shiny.tag
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" gloss_linetooltip(ex_sp, ex_gloss)
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" gloss_linetooltip(ex_sp, ex_gloss)
Takes a series of glosses from gloss_render()
and puts them in a list within one example for PDF output.
gloss_list(glist, listlabel = NULL)
gloss_list(glist, listlabel = NULL)
glist |
Concatenation of |
listlabel |
Label for the full list (optional) |
Character vector including the frame for a list of glosses.
These functions are output-specific and can be used to check the specific output
of certain calls, but are not meant to be used in an R Markdown file. Instead,
use as_gloss()
or gloss_df()
.
gloss_pdf(gloss) gloss_html(gloss, numbering = TRUE) gloss_tooltip(gloss, numbering = TRUE) gloss_leipzig(gloss, numbering = TRUE) gloss_word(gloss, numbering = TRUE)
gloss_pdf(gloss) gloss_html(gloss, numbering = TRUE) gloss_tooltip(gloss, numbering = TRUE) gloss_leipzig(gloss, numbering = TRUE) gloss_word(gloss, numbering = TRUE)
gloss |
Object of class |
numbering |
Whether the gloss should be numbered (in HTML and Word). |
Object of class gloss
.
gloss_pdf()
: Render in PDF
gloss_html()
: Render in HTML
gloss_tooltip()
: Tooltip rendering for HTML
gloss_leipzig()
: Leipzig.js engine
gloss_word()
: Render in Word
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" ex_trans <- "An example in Spanish" my_gloss <- new_gloss_data(list(ex_sp, ex_gloss), translation = ex_trans, label="ex1") gloss_pdf(my_gloss) gloss_html(my_gloss)
ex_sp <- "Un ejemplo en español" ex_gloss <- "DET.M.SG example in Spanish" ex_trans <- "An example in Spanish" my_gloss <- new_gloss_data(list(ex_sp, ex_gloss), translation = ex_trans, label="ex1") gloss_pdf(my_gloss) gloss_html(my_gloss)
A dataset containing five glossing examples extracted from Koptjevskaja-Tamm (2015)'s The Linguistics of Temperature and chapters within.
glosses
glosses
A tibble::tibble
with 5 rows and 6 variables:
The text in the original language.
The text with translations to English or morphological annotation per word or expression, with LaTeX formatting.
Free translation to English.
Label for referencing the example.
Original language of the text.
Where the example was taken from (published paper).
This method print gloss
objects with {knitr}
.
## S3 method for class 'gloss' knit_print(x, ...)
## S3 method for class 'gloss' knit_print(x, ...)
x |
Object to print |
... |
Other options |
The gloss
class contains how a gloss will be printed and its original input
(Object of class gloss_data
) as data
attribute.
It also has a knitr::knit_print()
method for rendering in R Markdown (and Quarto).
new_gloss(input, output)
new_gloss(input, output)
input |
A |
output |
How the gloss must be printed, depending on the output. |
Object of class gloss
.
Print the glossr configuration
print_config(config_sections = c("format", "pdf", "word", "other"))
print_config(config_sections = c("format", "pdf", "word", "other"))
config_sections |
Character vector with the following possible values:
|
Invisibly, a named list with the printed values
print_config() print_config("pdf") # print only pdf-specific configuration
print_config() print_config("pdf") # print only pdf-specific configuration
This is a helper function to set the configuration that control style characteristics
for glosses across the full document. It is called within use_glossr()
.
set_style_options(styling = list())
set_style_options(styling = list())
styling |
Named list of styling options for specific elements of glosses. |
There are five types of settings that can be provided in the list.
First, trans_quotes
sets the characters that must surround the free translation in a gloss.
If no value is specified, it will be double quotes. There are no real restrictions
for this value.
Second, the following elements can set general styling instructions for different
sections of a gloss, formatting them completely in italics OR bold. The items with a |
indicate that various names are possible.×
source|preamble: The line of the glosses where the source
is rendered.
a|first: The first line of the glosses, with the original language text.
b|second: The second line of the glosses.
c|third: The third line of the glosses if it exists.
ft|trans|translation: The line of the glosses where the free translation
is rendered.
Each of these items can take one of a few values:
i
, it
, italics
and textit
set italics.
b
, bf
, bold
and textbf
set boldface.
Third, there are a few LaTeX-specific settings documented in the expex documentation. In all cases the default value is 0 (0pt). (If you would like other settings to be supported, write up an Issue and I will look into it!)
exskip|par_spacing: Space above and below the example. The par_spacing
name
is allowed for backwards compatibility, but the actual name in expex
is exskip
.
belowglpreambleskip: Space under the preamble (where the source
is printed).
aboveglftskip: The spacing above the free translation.
extraglskip: The spacing between the aligned lines.
Fourth, there is one setting that is not available in LaTeX, particularly thinking of slides: numbering, that is, whether the glosses should be numbered (in HTML).
Finally, you may set the following values for Word output, used in computing the spaces for alignment:
font_family: A character vector of length 1 indicating the font family used in the lines to be aligned, or a list with names "a" and "b" (and "c" if relevant) indicating the font families of specific lines.
font_size: A numeric vector of length one indicating the font size used in the lines to be aligned, or a list with names "a" and "b" (and "c" if relevant) indicating the font sizes of specific lines.
page_width: The width of the space between the margins of the Word file, in pixels, used to wrap long examples. The default is 1332; if you see that your output does not match what you want, you can tweak it with this value.
set_style_options(styling = list(a = "b", trans_quotes = "'")) print_config()#'
set_style_options(styling = list(a = "b", trans_quotes = "'")) print_config()#'
Override default configuration.
use_glossr(output_format = NULL, styling = list())
use_glossr(output_format = NULL, styling = list())
output_format |
Desired output format |
styling |
Named list of styling options for specific elements of glosses. |
Set options
use_glossr(styling = list(numbering = FALSE, trans_quotes = "~")) print_config("other")
use_glossr(styling = list(numbering = FALSE, trans_quotes = "~")) print_config("other")