diff --git a/filter/tex/filter.php b/filter/tex/filter.php
index e02e906bd6e..54cbe8acc0c 100644
--- a/filter/tex/filter.php
+++ b/filter/tex/filter.php
@@ -40,13 +40,24 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
     if($alt==='') {
         $alt=s($tex);
     }
-// Given the path to a picture file in a course, or a URL,
+    // Given the path to a picture file in a course, or a URL,
     // this function includes the picture in the page.
     global $CFG;
 
     $output = "";
     $origtex = $tex;
-    $style = 'style="border:0px; vertical-align:'.$align.';';
+    if ($align !== 'middle') {
+        $style = ' style="vertical-align:'.$align.';';
+    } else {
+        $style = '';
+    }
+    if ($height) {
+        $style .= " height:{$height}px;";
+    }
+    if ($width) {
+        $style .= " width:{$width}px;";
+    }
+    $style .= '"';
     if ($tex) {
         $tex = str_replace('&','&',$tex);
         $tex = str_replace('<','&lt;',$tex);
@@ -60,13 +71,6 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
         // code. 
         $title = "title=\"$tex\"";
     }
-    if ($height) {
-        $style .= " height:{$height}px;";
-    }
-    if ($width) {
-        $style .= " width:{$width}px;";
-    }
-    $style .= '"';
     if ($imagefile) {
         if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
           $output .= "<a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">";
diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css
index b7fd9468465..64efb1ec98a 100644
--- a/theme/standard/styles_layout.css
+++ b/theme/standard/styles_layout.css
@@ -939,6 +939,10 @@ table.navbar {
   margin:0px;
   margin-left:0.5em;
 }
+.texrender {
+  border:0px;
+  vertical-align:middle;
+}
 
 
 /***