From 34d76407a531eca51762be53403c11bfdcccf3da Mon Sep 17 00:00:00 2001 From: Lukas Pirl Date: Tue, 26 May 2015 20:17:26 +0200 Subject: [PATCH] =?UTF-8?q?implemented=20rendering=20of=20math=20($?= =?UTF-8?q?=E2=80=A6$)=20in=20HTML=20via=20MathJax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bibtexbrowser.php | 64 +++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 4914678..bfc3ea7 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -56,6 +56,11 @@ function bibtexbrowser_configure($key, $value) { @define('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');// this is the name of a function @define('BIBLIOGRAPHYSECTIONS','DefaultBibliographySections');// this is the name of a function @define('BIBLIOGRAPHYTITLE','DefaultBibliographyTitle');// this is the name of a function + +// shall we load MathJax to render math in $…$ in HTML? +@define('BIBTEXBROWSER_RENDER_MATH', true); +@define('MATHJAX_URI', '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML.js'); + // can we load bibtex files on external servers? @define('BIBTEXBROWSER_LOCAL_BIB_ONLY', true); @@ -879,6 +884,13 @@ function char2html_case_sensitive($line,$latexmodifier,$char,$entitiyfragment) { */ function latex2html($line) { + $line = preg_replace('/([^\\\\])~/','\\1 ', $line); + + // performance increases with this test + // bug found by Serge Barral: what happens if we have curly braces only (typically to ensure case in Latex) + // added && strpos($line,'{')===false + if (strpos($line,'\\')===false && strpos($line,'{')===false) return $line; + $maths = array(); $index = 0; // first we escape the math env @@ -889,13 +901,6 @@ function latex2html($line) { $index++; } - $line = preg_replace('/([^\\\\])~/','\\1 ', $line); - - // performance increases with this test - // bug found by Serge Barral: what happens if we have curly braces only (typically to ensure case in Latex) - // added && strpos($line,'{')===false - if (strpos($line,'\\')===false && strpos($line,'{')===false) return $line; - // we should better replace this before the others // in order not to mix with the HTML entities coming after (just in case) $line = str_replace('\\&','&', $line); @@ -1699,7 +1704,7 @@ function get_HTML_tag_for_layout() { */ function bib2links_default(&$bibentry) { $links = array(); - + if (BIBTEXBROWSER_BIBTEX_LINKS) { $link = $bibentry->getBibLink(); if ($link != '') { $links[] = $link; }; @@ -1719,7 +1724,7 @@ function bib2links_default(&$bibentry) { $link = $bibentry->getGSLink(); if ($link != '') { $links[] = $link; }; } - + return ''.implode(" ",$links).''; } @@ -1963,7 +1968,7 @@ return .bibbooktitle { font-style:italic; } .bibauthor { } .bibpublisher { } - + See http://schema.org/ScholarlyArticle for the metadata */ function DefaultBibliographyStyle(&$bibentry) { @@ -2199,7 +2204,7 @@ function createQueryString($array_param) { if($key == Q_INNER_KEYS_INDEX) {continue;} $array_param[$key]=$key .'='. urlencode($val); } - + // adding the bibtex file name is not already there if (isset($_GET[Q_FILE]) && !isset($array_param[Q_FILE])) { // first we add the name of the bib file @@ -2319,6 +2324,19 @@ $('a.biburl').each(function() { // for each url "[bibtex]" } // end function javascript +if (!function_exists('javascript_math')) { + function javascript_math() { + ?> + + + searchView().'
'; @@ -2701,7 +2719,7 @@ class SimpleDisplay { return array(array('robots','noindex')); } } - + /** sets the entries to be shown */ function setEntries(&$entries) { $this->entries = $entries; @@ -2730,8 +2748,8 @@ class SimpleDisplay { function setQuery($query) { $this->query = $query; } - function getTitle() { - return _DefaultBibliographyTitle($this->query); + function getTitle() { + return _DefaultBibliographyTitle($this->query); } /** Displays a set of bibtex entries in an HTML table */ @@ -2894,7 +2912,7 @@ class AcademicDisplay { $display->incHeadingLevel(); $display->setEntries($entries); $display->headerCSS = 'theader'; - + $sections[] = array ( 'display' => $display, 'anchor' => $anchor, @@ -3385,7 +3403,7 @@ class BibDataBase { $result[$key] = $year; } - + krsort($result); return $result; } @@ -3704,6 +3722,10 @@ if (method_exists($content, 'getTitle')) { if (BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT) { javascript(); } + + if (BIBTEXBROWSER_RENDER_MATH) { + javascript_math(); + } ?> @@ -3754,7 +3776,7 @@ class BibtexDisplay { foreach($this->entries as $bibentry) { echo $bibentry->getText()."\n"; } exit; } - + } /** creates paged output, e.g: [[http://localhost/bibtexbrowser/testPagedDisplay.php?page=1]] @@ -3975,20 +3997,20 @@ class Dispatcher { /** The BibDataBase object */ var $db = null; - + function Dispatcher() {} /** returns the underlying BibDataBase object */ function getDB() { // by default set it from $_GET[Q_FILE] // first we set the database (load from disk or parse the bibtex file) - if ($this->db == null) { + if ($this->db == null) { list($db, $parsed, $updated, $saved) = _zetDB($_GET[Q_FILE]); $this->db = $db; } return $this->db; } - + function main() { // are we in test mode, or libray mode // then this file is just a library