O3PO_Latex_Dictionary_Provider
in package
This class provides various dictionaries that O3PO_Latex needs to do its job.
Tags
Table of Contents
Properties
- $latex_clean_up_dictionary : mixed
- LaTeX cleanup dictionary
- $latex_special_chars_dictionary : array<string|int, mixed>
- An associative array of regular expressions that match latex code and utf8 representations of the respective symbol they represent
- $latex_special_chars_reverse_dictionary : mixed
- Associative array of utf8 representations and their respective LaTeX representations.
- $utf8_to_ascii_dictionary : mixed
- Associative array of utf8 representations and their closest ascii characters.
Methods
- expand_cite_to_html() : mixed
- Expand \cite{} commands to html code.
- extract_abstracts() : mixed
- Extract all abstracts from latex code.
- extract_bibliographies() : mixed
- Extract all bibliographies from latex code.
- get_latex_clean_up_dictionary() : mixed
- Get the $latex_clean_up_dictionary.
- get_latex_special_chars_dictionary() : mixed
- Get the $latex_special_chars_dictionary.
- get_latex_special_chars_reverse_dictionary() : mixed
- Get the $latex_special_chars_reverse_dictionary.
- get_utf8_to_ascii_dictionary() : mixed
- Get the $utf8_to_ascii_dictionary.
- normalize_whitespace_and_linebreak_characters() : mixed
- Normalized white space and line break characters.
- remove_font_changing_commands() : mixed
- Remove font changing commands.
- un_escape_url() : string
- Un-escape a LaTeX style escaped url.
- match_single_character_makro_regexp_fragment() : mixed
- Utility function to construct the $latex_special_chars_dictionary.
- match_single_non_character_makro_regexp_fragment() : mixed
- Utility function to construct the $latex_special_chars_dictionary.
Properties
$latex_clean_up_dictionary
LaTeX cleanup dictionary
private
static mixed
$latex_clean_up_dictionary
= array(
//'>' => '\gt ', leave these alone outside of math mode so that they can
//'<' => '\lt ', later be caught by esc_html() and finalyl printed by MathJax
'~' => ' ',
'---' => '—',
'--' => '–',
'\%' => '%',
'\#' => '#',
'\_' => '_',
'\ ' => ' ',
"\\\n" => "\n",
"\\\r" => "\r",
'{' => '',
'}' => '',
)
After we have performed the above replacements in the following function we clean up remaining special characters accoding to the following list.
Tags
$latex_special_chars_dictionary
An associative array of regular expressions that match latex code and utf8 representations of the respective symbol they represent
private
static array<string|int, mixed>
$latex_special_chars_dictionary
= \null
As PHP does not allow the initialization of static variables from static member methods we have to initialize this array to null. You may thus never use this variable directly, instead use the getter method below.
An associative array of regular expressions that match latex code and utf8 representations of the respective symbol they represent
Tags
$latex_special_chars_reverse_dictionary
Associative array of utf8 representations and their respective LaTeX representations.
private
static mixed
$latex_special_chars_reverse_dictionary
= array('á' => '{\\\\\'{a}}', 'é' => '{\\\\\'{e}}', 'í' => '{\\\\\'{i}}', 'ó' => '{\\\\\'{o}}', 'ú' => '{\\\\\'{u}}', 'ć' => '{\\\\\'{c}}', 'Á' => '{\\\\\'{A}}', 'Ć' => '{\\\\\'{C}}', 'É' => '{\\\\\'{E}}', 'Í' => '{\\\\\'{I}}', 'Ó' => '{\\\\\'{O}}', 'Ú' => '{\\\\\'{U}}', 'ä' => '{\\\\"{a}}', 'ï' => '{\\\\"{i}}', 'ë' => '{\\\\"{e}}', 'ö' => '{\\\\"{o}}', 'ü' => '{\\\\"{u}}', 'â' => '{\\\\^{a}}', 'ĉ' => '{\\\\^{c}}', 'ê' => '{\\\\^{e}}', 'ô' => '{\\\\^{o}}', 'à' => '{\\\\`{a}}', 'è' => '{\\\\`{e}}', 'ò' => '{\\\\`{o}}', 'ù' => '{\\\\`{u}}', 'ì' => '{\\\\`{i}}', 'č' => '{\\\\v{c}}', 'ß' => '{\\\\ss{}}', 'Ł' => '{\\\\L{}}', 'ł' => '{\\\\l{}}', 'ø' => '{\\\\o{}}', 'Ø' => '{\\\\O{}}', 'å' => '{\\\\aa{}}', 'Å' => '{\\\\AA{}}', 'Š' => '{\\\\v{S}}', 'š' => '{\\\\v{s}}', 'Ä' => '{\\\\"{A}}', 'Ë' => '{\\\\"{E}}', 'Ï' => '{\\\\"{I}}', 'Ö' => '{\\\\"{O}}', 'Ü' => '{\\\\"{U}}', 'ç' => '{\\\\c{c}}', 'Ç' => '{\\\\c{C}}', 'ǵ' => '{\\\\\'{g}}', 'ĺ' => '{\\\\\'{l}}', 'ń' => '{\\\\\'{n}}', 'ŕ' => '{\\\\\'{r}}', 'ś' => '{\\\\\'{s}}', 'ý' => '{\\\\\'{y}}', 'ź' => '{\\\\\'{z}}', 'Ĺ' => '{\\\\\'{L}}', 'Ń' => '{\\\\\'{N}}', 'Ŕ' => '{\\\\\'{R}}', 'Ś' => '{\\\\\'{S}}', 'Ý' => '{\\\\\'{Y}}', 'Ź' => '{\\\\\'{Z}}', 'Ċ' => '{\\\\.{C}}', 'Ė' => '{\\\\.{E}}', 'Ġ' => '{\\\\.{G}}', 'İ' => '{\\\\.{I}}', 'Ż' => '{\\\\.{Z}}', 'ċ' => '{\\\\.{c}}', 'ė' => '{\\\\.{e}}', 'ġ' => '{\\\\.{g}}', 'ż' => '{\\\\.{z}}', 'Ā' => '{\\\\={A}}', 'Ē' => '{\\\\={E}}', 'Ī' => '{\\\\={I}}', 'Ō' => '{\\\\={O}}', 'Ū' => '{\\\\={U}}', 'ā' => '{\\\\={a}}', 'ē' => '{\\\\={e}}', 'ō' => '{\\\\={o}}', 'ū' => '{\\\\={u}}', 'Ÿ' => '{\\\\"{Y}}', 'ÿ' => '{\\\\"{y}}', 'Â' => '{\\\\^{A}}', 'Ĉ' => '{\\\\^{C}}', 'Ê' => '{\\\\^{E}}', 'Ĝ' => '{\\\\^{G}}', 'Ĥ' => '{\\\\^{H}}', 'Î' => '{\\\\^{I}}', 'Ĵ' => '{\\\\^{J}}', 'Ô' => '{\\\\^{O}}', 'Ŝ' => '{\\\\^{S}}', 'Û' => '{\\\\^{U}}', 'Ŵ' => '{\\\\^{W}}', 'Ŷ' => '{\\\\^{Y}}', 'ĝ' => '{\\\\^{g}}', 'ĥ' => '{\\\\^{h}}', 'ô' => '{\\\\^{o}}', 'ŝ' => '{\\\\^{s}}', 'û' => '{\\\\^{u}}', 'ŵ' => '{\\\\^{w}}', 'ŷ' => '{\\\\^{y}}', 'À' => '{\\\\`{A}}', 'È' => '{\\\\`{E}}', 'Ì' => '{\\\\`{I}}', 'Ò' => '{\\\\`{O}}', 'Ù' => '{\\\\`{U}}', 'Ą' => '{\\\\k{A}}', 'Ę' => '{\\\\k{E}}', 'Į' => '{\\\\k{I}}', 'Ų' => '{\\\\k{U}}', 'ą' => '{\\\\k{a}}', 'ę' => '{\\\\k{e}}', 'į' => '{\\\\k{i}}', 'ų' => '{\\\\k{u}}', 'Ă' => '{\\\\u{A}}', 'Ĕ' => '{\\\\u{E}}', 'Ğ' => '{\\\\u{G}}', 'Ĭ' => '{\\\\u{I}}', 'Ŏ' => '{\\\\u{O}}', 'Ŭ' => '{\\\\u{U}}', 'ă' => '{\\\\u{a}}', 'ĕ' => '{\\\\u{e}}', 'ğ' => '{\\\\u{g}}', 'ŏ' => '{\\\\u{o}}', 'ŭ' => '{\\\\u{u}}', 'Č' => '{\\\\v{C}}', 'Ď' => '{\\\\v{D}}', 'Ě' => '{\\\\v{E}}', 'Ľ' => '{\\\\v{L}}', 'Ň' => '{\\\\v{N}}', 'Ř' => '{\\\\v{R}}', 'Ť' => '{\\\\v{T}}', 'Ž' => '{\\\\v{Z}}', 'ď' => '{\\\\v{d}}', 'ě' => '{\\\\v{e}}', 'ľ' => '{\\\\v{l}}', 'ň' => '{\\\\v{n}}', 'ř' => '{\\\\v{r}}', 'ť' => '{\\\\v{t}}', 'ž' => '{\\\\v{z}}', 'Ã' => '{\\\\~{A}}', 'Ĩ' => '{\\\\~{I}}', 'Ñ' => '{\\\\~{N}}', 'Õ' => '{\\\\~{O}}', 'Ũ' => '{\\\\~{U}}', 'ã' => '{\\\\~{a}}', 'ñ' => '{\\\\~{n}}', 'õ' => '{\\\\~{o}}', 'ũ' => '{\\\\~{u}}', 'ţ' => '{\\\\c{t}}', 'ş' => '{\\\\c{s}}', 'ŗ' => '{\\\\c{r}}', 'ņ' => '{\\\\c{n}}', 'ļ' => '{\\\\c{l}}', 'ķ' => '{\\\\c{k}}', 'ģ' => '{\\\\c{g}}', 'Ţ' => '{\\\\c{T}}', 'Ş' => '{\\\\c{S}}', 'Ŗ' => '{\\\\c{R}}', 'Ņ' => '{\\\\c{N}}', 'Ļ' => '{\\\\c{L}}', 'Ķ' => '{\\\\c{K}}', 'Ģ' => '{\\\\c{G}}')
In some cases we need to generate LaTeX code from utf-8 encoded strings containing special characters. This array helps in doing this.
Tags
$utf8_to_ascii_dictionary
Associative array of utf8 representations and their closest ascii characters.
private
static mixed
$utf8_to_ascii_dictionary
= array('á' => 'a', 'é' => 'e', 'í' => 'i', 'ó' => 'o', 'ú' => 'u', 'ć' => 'c', 'Á' => 'A', 'Ć' => 'C', 'É' => 'E', 'Í' => 'I', 'Ó' => 'O', 'Ú' => 'U', 'ä' => 'a', 'ï' => 'i', 'ë' => 'e', 'ö' => 'o', 'ü' => 'u', 'â' => 'a', 'ĉ' => 'c', 'ê' => 'e', 'à' => 'a', 'è' => 'e', 'ò' => 'o', 'ù' => 'u', 'ì' => 'i', 'č' => 'c', 'ß' => 'ss', 'Ł' => 'L', 'ł' => 'l', 'ø' => 'o', 'Ø' => 'O', 'å' => 'a', 'Å' => 'A', 'Š' => 'S', 'š' => 's', 'Ä' => 'A', 'Ë' => 'E', 'Ï' => 'I', 'Ö' => 'O', 'Ü' => 'U', 'ç' => 'c', 'Ç' => 'C', 'ǵ' => 'g', 'ĺ' => 'l', 'ń' => 'n', 'ŕ' => 'r', 'ś' => 's', 'ý' => 'y', 'ź' => 'z', 'Ĺ' => 'L', 'Ń' => 'N', 'Ŕ' => 'R', 'Ś' => 'S', 'Ý' => 'Y', 'Ź' => 'Z', 'Ċ' => 'C', 'Ė' => 'E', 'Ġ' => 'G', 'İ' => 'I', 'Ż' => 'Z', 'ċ' => 'c', 'ė' => 'e', 'ġ' => 'g', 'ż' => 'z', 'Ā' => 'A', 'Ē' => 'E', 'Ī' => 'I', 'Ō' => 'O', 'Ū' => 'U', 'ā' => 'a', 'ē' => 'e', 'ō' => 'o', 'ū' => 'u', 'Ÿ' => 'Y', 'ÿ' => 'y', 'Â' => 'A', 'Ĉ' => 'C', 'Ê' => 'E', 'Ĝ' => 'G', 'Ĥ' => 'H', 'Î' => 'I', 'Ĵ' => 'J', 'Ô' => 'O', 'Ŝ' => 'S', 'Û' => 'U', 'Ŵ' => 'W', 'Ŷ' => 'Y', 'ĝ' => 'g', 'ĥ' => 'h', 'ô' => 'o', 'ŝ' => 's', 'û' => 'u', 'ŵ' => 'w', 'ŷ' => 'y', 'À' => 'A', 'È' => 'E', 'Ì' => 'I', 'Ò' => 'O', 'Ù' => 'U', 'Ą' => 'A', 'Ę' => 'E', 'Į' => 'I', 'Ų' => 'U', 'ą' => 'a', 'ę' => 'e', 'į' => 'i', 'ų' => 'u', 'Ă' => 'A', 'Ĕ' => 'E', 'Ğ' => 'G', 'Ĭ' => 'I', 'Ŏ' => 'O', 'Ŭ' => 'U', 'ă' => 'a', 'ĕ' => 'e', 'ğ' => 'g', 'ŏ' => 'o', 'ŭ' => 'u', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ľ' => 'L', 'Ň' => 'N', 'Ř' => 'R', 'Ť' => 'T', 'Ž' => 'Z', 'ď' => 'd', 'ě' => 'e', 'ľ' => 'l', 'ň' => 'n', 'ř' => 'r', 'ť' => 't', 'ž' => 'z', 'Ã' => 'A', 'Ĩ' => 'I', 'Ñ' => 'N', 'Õ' => 'O', 'Ũ' => 'U', 'ã' => 'a', 'ñ' => 'n', 'õ' => 'o', 'ũ' => 'u', 'ţ' => 't', 'ş' => 's', 'ŗ' => 'r', 'ņ' => 'n', 'ļ' => 'l', 'ķ' => 'k', 'ģ' => 'g', 'Ţ' => 'T', 'Ş' => 'S', 'Ŗ' => 'R', 'Ņ' => 'N', 'Ļ' => 'L', 'Ķ' => 'K', 'Ģ' => 'G')
In some cases we need to generate ascii strings from utf-8 encoded strings containing special characters. This array helps in doing this.
Tags
Methods
expand_cite_to_html()
Expand \cite{} commands to html code.
public
static expand_cite_to_html(string $text, string $bbl) : mixed
The resulting html code makes every \cite a clickable hyperlink to the correspnding entry in the bibliograhy.
Parameters
- $text : string
-
The text in which \cite commands are to be expanded
- $bbl : string
-
The bbl code of the bibliography that contains the corresponding bibliography entries.
Tags
extract_abstracts()
Extract all abstracts from latex code.
public
static extract_abstracts(string $latex) : mixed
Parameters
- $latex : string
-
Latex code to search for abstracts.
Tags
extract_bibliographies()
Extract all bibliographies from latex code.
public
static extract_bibliographies(string $latex) : mixed
Parameters
- $latex : string
-
Latex code to search for bibliographies.
Tags
get_latex_clean_up_dictionary()
Get the $latex_clean_up_dictionary.
public
static get_latex_clean_up_dictionary() : mixed
Tags
get_latex_special_chars_dictionary()
Get the $latex_special_chars_dictionary.
public
static get_latex_special_chars_dictionary() : mixed
We are dealing with a lot of LaTeX code in wich special characters are LaTeX encoded. On our website we want to display them in a pretty way. The following is a (more or less complete) mapping of LaTeX encodigs into utf-8 characters whenever such a character is available. This list must only contain latex macros that contain a \ as for preformance reasons replacing is stopped once all \ have been eliminated. Also there is a negative look must be added when using this dictionary to prevent replacements in cases such as \v{a}.
Tags
get_latex_special_chars_reverse_dictionary()
Get the $latex_special_chars_reverse_dictionary.
public
static get_latex_special_chars_reverse_dictionary() : mixed
Tags
get_utf8_to_ascii_dictionary()
Get the $utf8_to_ascii_dictionary.
public
static get_utf8_to_ascii_dictionary() : mixed
Tags
normalize_whitespace_and_linebreak_characters()
Normalized white space and line break characters.
public
static normalize_whitespace_and_linebreak_characters(string $text[, bool $single_line = true ][, bool $remove_extra_newlines = false ]) : mixed
Parameters
- $text : string
-
LaTeX text to normalize.
- $single_line : bool = true
-
Whether to output a single-line text.
- $remove_extra_newlines : bool = false
-
If true, single newlines are replaced by space and any number of more than two successive newlines are replaced by exactly two newlines.
Tags
remove_font_changing_commands()
Remove font changing commands.
public
static remove_font_changing_commands(string $text) : mixed
Parameters
- $text : string
-
LaTeX text to remove font commands from.
Tags
un_escape_url()
Un-escape a LaTeX style escaped url.
public
static un_escape_url(string $latex_url) : string
Parameters
- $latex_url : string
-
LaTeX style escaped url.
Tags
Return values
string —Url without LaTeX escape sequences.
match_single_character_makro_regexp_fragment()
Utility function to construct the $latex_special_chars_dictionary.
private
static match_single_character_makro_regexp_fragment(string $char) : mixed
Parameters
- $char : string
-
The character characteristic to the respective latex macro.
Tags
match_single_non_character_makro_regexp_fragment()
Utility function to construct the $latex_special_chars_dictionary.
private
static match_single_non_character_makro_regexp_fragment(string $char) : mixed
Parameters
- $char : string
-
The non-character symbol characteristic to the respective latex macro.