Add this modification to style block vs inline differently
-
A missing feature is to be able to style inline equations differently than block or stand alone equations. in the following code, I allow for a “isblock’ flag, which adds an additional class tag: “latex_block”.
// [latex size=0 color=000000 background=ffffff isblock=true]\LaTeX[/latex]
// Shortcode -> <img> markup. Creates images as necessary.
function shortcode( $_atts, $latex ) {
$atts = shortcode_atts( array(
‘size’ => 0,
‘color’ => false,
‘background’ => false,
‘isblock’ => false,
), $_atts );$latex = preg_replace( array( ‘#<br\s*/?>#i’, ‘#</?p>#i’ ), ‘ ‘, $latex );
$latex = str_replace(
array( ‘<‘, ‘>’, ‘"’, ‘“’, ‘”’, ‘'’, ‘᾽’, ‘᾿’, ‘’’, ‘&’, ‘&’, “\n”, “\r”, “\xa0”, ‘–’ ),
array( ‘<‘, ‘>’, ‘”‘, ‘‘, “””, “‘”, “‘”, “‘”, “‘”, ‘&’, ‘&’, ‘ ‘, ‘ ‘, ‘ ‘, ‘-‘ ),
$latex
);$latex_object = $this->latex( $latex, $atts[‘background’], $atts[‘color’], $atts[‘size’] );
$url = esc_url( $latex_object->url );
$alt = esc_attr( is_wp_error($latex_object->error) ? $latex_object->error->get_error_message() . “: $latex_object->latex” : $latex_object->latex );
// added by tim
$classString = $atts[‘isblock’] ? “latex latex_block” : “latex”;return “<img src=’$url’ alt=’$alt’ title=’$alt’ class=’$classString’ />”;
}Then you can add css such as this:
img.latex_block {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 30px;
}Pleas consider adding this. Thanks!
- The topic ‘Add this modification to style block vs inline differently’ is closed to new replies.