Browse Source

fix math expression problems

pull/117/head
Martin Monperrus 4 years ago
parent
commit
a1d4f6c843
  1. 16
      BibtexbrowserTest.php
  2. 35
      bibtexbrowser.php

16
BibtexbrowserTest.php

@ -141,7 +141,7 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
// IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n ",strip_tags($first_entry->toHTML()));
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", New Results, vol. 5, pp. 1-2, 2009.\n ",strip_tags($first_entry->toHTML()));
$css_classes_after = $this->extract_css_classes($first_entry->toHTML());
// contract: make sure the Janos style and default style use the same CSS classes
$this->assertEquals($css_classes_before, $css_classes_after);
@ -846,6 +846,20 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected,$entry->toCFF());
}
function test_uppercase() {
print(preg_replace_callback('/\\\\uppercase\{(.*)\}/',"strtolowercallback", "$\uppercase{B}"));
$bibtex = "@article{doe2000,title={Preferential polarization and its reversal in polycrystalline $\uppercase{B}i\uppercase{F}e\uppercase{O}_{3}$/$\uppercase{L}a_{0. 5}\uppercase{S}r_{0.5} \uppercase{C}o\uppercase{O}_{3}$ heterostructures},author={Jane Doe},journal={The Wordpress Journal},year=2000}";
$test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex);
fseek($test_data,0);
$db = new BibDataBase();
$_GET[Q_FILE] = 'sample.bib';
$db->update_internal("inline", $test_data);
$this->assertEquals('Preferential polarization and its reversal in polycrystalline $BiFeO_{3}$/$La_{0. 5}Sr_{0.5} CoO_{3}$ heterostructures', $db->bibdb['doe2000']->getTitle());
}
} // end class

35
bibtexbrowser.php

@ -997,6 +997,21 @@ function latex2html($line, $do_clean_extra_bracket=true) {
// added && strpos($line,'{')===false
if (strpos($line,'\\')===false && strpos($line,'{')===false) return $line;
// handling uppercase
// echo preg_replace_callback('!\b[a-z]!', 'upper', strtolower($str));
if (!function_exists("strtolowercallback")) {
function strtolowercallback($array) {
return strtolower($array[1]);
}
}
if (!function_exists("strtouppercallback")) {
function strtouppercallback($array) {
return strtoupper($array[1]);
}
}
$line = preg_replace_callback('/\\\\uppercase\{(.*)\}/U',"strtouppercallback", $line);
$line = preg_replace_callback('/\\\\lowercase\{(.*)\}/U',"strtolowercallback", $line);
$maths = array();
$index = 0;
// first we escape the math env
@ -1087,6 +1102,8 @@ function latex2html($line, $do_clean_extra_bracket=true) {
// handling \textsubscript{....} FAILS if there still are nested {}
$line = preg_replace('/\\\\textsubscript\{(.*)\}/U','<sub>\\1</sub>', $line);
if ($do_clean_extra_bracket) {
// clean extra tex curly brackets, usually used for preserving capitals
// must come before the final math replacement
@ -2452,7 +2469,7 @@ function JanosBibliographyStyle($bibentry) {
}
if ($type=="article" && $bibentry->hasField("journal")) {
$booktitle = '<span class="bibbooktitle">'.'In '.$bibentry->getField("journal").'</span>';
$booktitle = '<span class="bibbooktitle">'.''.$bibentry->getField("journal").'</span>';
}
@ -2774,12 +2791,16 @@ $('a.biburl').each(function() { // for each url "[bibtex]"
if (!function_exists('javascript_math')) {
function javascript_math() {
?>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [["$","$"]]}
});
</script>
<script src="<?php echo MATHJAX_URI ?>"></script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
<?php
}
}

Loading…
Cancel
Save