Physikerwelt has submitted this change and it was merged. Change subject: Displaystyle ......................................................................
Displaystyle Adds a displaystyle option for the math tag. Bug: 12223 Change-Id: Ic73a93141a64d7f0280d12f364efa63df8dbca6e --- M MathLaTeXML.php M MathRenderer.php M MathTexvc.php M math/texutil.ml 4 files changed, 79 insertions(+), 13 deletions(-) Approvals: Physikerwelt: Looks good to me, approved diff --git a/MathLaTeXML.php b/MathLaTeXML.php index 9672fd6..51bdc4f 100644 --- a/MathLaTeXML.php +++ b/MathLaTeXML.php @@ -211,7 +211,13 @@ * @return string HTTP POST data */ public function getPostData() { - $texcmd = urlencode( $this->tex ); + $tex = $this->tex; + if ($this->getDisplaytyle()){ + if (! $this->guessDisplaytyleFromTex() ){ + $tex = '{\displaystyle '. $tex . '}'; + } + } + $texcmd = urlencode($tex); $settings = $this->serializeSettings($this->getLaTeXMLSettings()); return $settings. '&tex=' . $texcmd; } @@ -287,7 +293,13 @@ * @return html element with rendered math */ private function getMathMLTag() { - return self::embedMathML( $this->getMathml(), urldecode( $this->getTex() ) ); + if ( $this->getDisplaytyle() ){ + $mml = preg_replace('|display="inline"|', 'display="block"', $this->getMathml()); + $mml = preg_replace('/mode="(inline|block)"/', 'display="block"', $mml); + } else { + $mml = $this->getMathml(); + } + return self::embedMathML( $mml, urldecode( $this->getTex() ) ); } /** diff --git a/MathRenderer.php b/MathRenderer.php index b8a5148..d7cfccd 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -48,6 +48,13 @@ protected $statusCode = 0; protected $timestamp; protected $texSecure = false; + /** + * + * @var boolean by default all equations are rendered in inline style + * set to true for displaystyle + */ + protected $displaytyle = true; + private $displaystyleIndicators = array( '\displaystyle', '\begin' ); /** * Constructs a base MathRenderer @@ -101,6 +108,17 @@ $renderer = new MathTexvc( $tex, $params ); } wfDebugLog ( "Math", 'start rendering $' . $renderer->tex . '$ in mode ' . $mode ); + if ( isset($params['display']) ){ + $layoutMode = $params['display']; + if( $layoutMode == 'inline' ){ + $renderer->setDisplaytyle( false ); + //if the user has not specified how displaystyle should be obtained this method is used + if(! $renderer->guessDisplaytyleFromTex()){ + $tex= '{\textstyle'. $tex.'}'; + $renderer->setTex( $tex ); + } + } + } return $renderer; } @@ -185,7 +203,7 @@ } /** - * + * * @param database_row $rpage */ public function initializeFromDatabaseRow( $rpage ) { @@ -262,7 +280,7 @@ wfDebugLog ( "Math", "Store Data:" . var_export ( $out, true ) . "\n\n" ); return $out; } - + /** * Returns sanitized attributes * @@ -455,14 +473,29 @@ function getLastError(){ return $this->lastError; } - + /** * @return string */ public function getLog() { return $this->log; } - + /** + * + * @param boolean $displaytyle + */ + public function setDisplaytyle( $displaystyle= true ){ + $this->changed = true; //Discuss if this is a change + $this->displaytyle = $displaystyle; + } + /** + * + * @param boolean $displaytyle + */ + public function getDisplaytyle(){ + return $this->displaytyle; + } + /** * @param string $log */ @@ -470,7 +503,7 @@ $this->changed = true; $this->log = $log; } - + /** * @param int $timestamp */ @@ -478,14 +511,14 @@ $this->changed = true; $this->timestamp = $timestamp; } - + /** * @return int */ public function getStatusCode() { return $this->statusCode; } - + /** * @param unknown_type $statusCode */ @@ -501,7 +534,7 @@ public function isTexSecure (){ return $this->texSecure; } - + public function checkTex(){ $this->texSecure = false; //TODO Update tex checking @@ -518,5 +551,22 @@ } } + + + /** + * Checks if there are indicators in the tex code speified be the user + * that the math tag (or part of it) should be rendered in a kind of + * displaystyle. + * @return boolean (true if displaystyle indicators are found) + */ + protected function guessDisplaytyleFromTex(){ + $tex= $this->getTex(); + foreach ($this->displaystyleIndicators as $indicator) { + if ( strpos($tex, $indicator) !== false){ + return true; + } + } + return false; + } } diff --git a/MathTexvc.php b/MathTexvc.php index d737e04..4f4bbd2 100644 --- a/MathTexvc.php +++ b/MathTexvc.php @@ -91,13 +91,17 @@ */ public function getMathImageHTML() { $url = $this->getMathImageUrl(); - + $style = ''; + if ($this->getDisplaytyle()){ + $style = 'display:block;margin:auto'; + } return Xml::element( 'img', $this->getAttributes( 'img', array( 'class' => 'tex', 'alt' => $this->getTex(), + 'style'=>$style ), array( 'src' => $url @@ -347,7 +351,7 @@ } /** - * + * * @return string texvc secured tex code */ public function getSecureTex(){ diff --git a/math/texutil.ml b/math/texutil.ml index a4c40a5..546c017 100644 --- a/math/texutil.ml +++ b/math/texutil.ml @@ -47,7 +47,7 @@ let modules_encoding = ref UTF8 let modules_color = ref false let modules_teubner = ref false -let modules_euro = ref false +let modules_euro = ref false (* wrappers to easily set / reset module properties *) let tex_use_ams () = modules_ams := true -- To view, visit https://gerrit.wikimedia.org/r/84629 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic73a93141a64d7f0280d12f364efa63df8dbca6e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Math Gerrit-Branch: dev Gerrit-Owner: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: Frédéric Wang <fred.w...@free.fr> Gerrit-Reviewer: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits