PATH:
home
/
lab2454c
/
mact34.com
/
wp-content
/
plugins
/
jetpack
/
modules
<?php /** * Module Name: Beautiful Math * Module Description: Use the LaTeX markup language to write mathematical equations and formulas * Sort Order: 12 * First Introduced: 1.1 * Requires Connection: No * Auto Activate: No * Module Tags: Writing * Feature: Writing * Additional Search Queries: latex, math, equation, equations, formula, code */ /** * LaTeX support. * * Backward compatibility requires support for both "[latex][/latex]", and * "$latex $" shortcodes. * * $latex e^{\i \pi} + 1 = 0$ -> [latex]e^{\i \pi} + 1 = 0[/latex] * $latex [a, b]$ -> [latex][a, b][/latex] */ function latex_markup( $content ) { $textarr = wp_html_split( $content ); $regex = '% \$latex(?:=\s*|\s+) ((?: [^$]+ # Not a dollar | (?<=(?<!\\\\)\\\\)\$ # Dollar preceded by exactly one slash )+) (?<!\\\\)\$ # Dollar preceded by zero slashes %ix'; foreach ( $textarr as &$element ) { if ( '' == $element || '<' === $element[0] ) { continue; } if ( false === stripos( $element, '$latex' ) ) { continue; } $element = preg_replace_callback( $regex, 'latex_src', $element ); } return implode( '', $textarr ); } function latex_src( $matches ) { $latex = $matches[1]; $bg = latex_get_default_color( 'bg' ); $fg = latex_get_default_color( 'text', '000' ); $s = 0; $latex = latex_entity_decode( $latex ); if ( preg_match( '/.+(&fg=[0-9a-f]{6}).*/i', $latex, $fg_matches ) ) { $fg = substr( $fg_matches[1], 4 ); $latex = str_replace( $fg_matches[1], '', $latex ); } if ( preg_match( '/.+(&bg=[0-9a-f]{6}).*/i', $latex, $bg_matches ) ) { $bg = substr( $bg_matches[1], 4 ); $latex = str_replace( $bg_matches[1], '', $latex ); } if ( preg_match( '/.+(&s=[0-9-]{1,2}).*/i', $latex, $s_matches ) ) { $s = (int) substr( $s_matches[1], 3 ); $latex = str_replace( $s_matches[1], '', $latex ); } return latex_render( $latex, $fg, $bg, $s ); } function latex_get_default_color( $color, $default_color = 'ffffff' ) { global $themecolors; return isset($themecolors[$color]) ? $themecolors[$color] : $default_color; } function latex_entity_decode( $latex ) { return str_replace( array( '<', '>', '"', ''', '&', '&', "\n", "\r" ), array( '<', '>', '"', "'", '&', '&', ' ', ' ' ), $latex ); } /** * Returns the URL for the server-side rendered image of LaTeX. * * @param string $latex LaTeX string. * @param string $fg Foreground color. * @param string $bg Background color. * @param int $s Matches. * * @return string Image URL for the rendered LaTeX. */ function latex_render( $latex, $fg, $bg, $s = 0 ) { $url = add_query_arg( urlencode_deep( array( 'latex' => $latex, 'bg' => $bg, 'fg' => $fg, 's' => $s, 'c' => '20201002', // cache buster. Added 2020-10-02 after server migration caused faulty rendering. ) ), ( is_ssl() ? 'https://' : 'http://' ) . 's0.wp.com/latex.php' ); $alt = str_replace( '\\', '\', esc_attr( $latex ) ); return sprintf( '<img src="%1$s" alt="%2$s" class="latex" />', esc_url( $url ), $alt ); } /** * The shortcode way. The attributes are the same as the old ones - 'fg' and 'bg', instead of foreground * and background, and 's' is for the font size. * * Example: [latex s=4 bg=00f fg=ff0]\LaTeX[/latex] */ function latex_shortcode( $atts, $content = '' ) { extract( shortcode_atts( array( 's' => 0, 'bg' => latex_get_default_color( 'bg' ), 'fg' => latex_get_default_color( 'text', '000' ) ), $atts, 'latex' ) ); return latex_render( latex_entity_decode( $content ), $fg, $bg, $s ); } /** * LaTeX needs to be untexturized */ function latex_no_texturize( $shortcodes ) { $shortcodes[] = 'latex'; return $shortcodes; } add_filter( 'no_texturize_shortcodes', 'latex_no_texturize' ); add_filter( 'the_content', 'latex_markup', 9 ); // before wptexturize add_filter( 'comment_text', 'latex_markup', 9 ); // before wptexturize add_shortcode( 'latex', 'latex_shortcode' );
[+]
publicize
[+]
photon-cdn
[-] module-headings.php
[edit]
[+]
search
[-] shortcodes.php
[edit]
[-] lazy-images.php
[edit]
[-] minileven.php
[edit]
[+]
site-icon
[-] notes.php
[edit]
[+]
verification-tools
[-] carousel.php
[edit]
[+]
widgets
[+]
plugin-search
[+]
likes
[-] monitor.php
[edit]
[-] geo-location.php
[edit]
[-] seo-tools.php
[edit]
[-] search.php
[edit]
[-] enhanced-distribution.php
[edit]
[+]
theme-tools
[+]
custom-post-types
[-] subscriptions.php
[edit]
[+]
sitemaps
[-] post-by-email.php
[edit]
[-] gravatar-hovercards.php
[edit]
[-] videopress.php
[edit]
[+]
..
[-] shortlinks.php
[edit]
[+]
subscriptions
[-] module-extras.php
[edit]
[-] custom-css.php
[edit]
[-] publicize.php
[edit]
[+]
videopress
[-] latex.php
[edit]
[-] woocommerce-analytics.php
[edit]
[-] widgets.php
[edit]
[-] module-info.php
[edit]
[+]
tiled-gallery
[+]
google-analytics
[-] json-api.php
[edit]
[+]
scan
[+]
contact-form
[-] infinite-scroll.php
[edit]
[-] comment-likes.php
[edit]
[-] tiled-gallery.php
[edit]
[-] plugin-search.php
[edit]
[-] sharedaddy.php
[edit]
[-] sitemaps.php
[edit]
[-] masterbar.php
[edit]
[-] contact-form.php
[edit]
[+]
simple-payments
[-] photon-cdn.php
[edit]
[+]
post-by-email
[-] custom-content-types.php
[edit]
[+]
carousel
[-] widget-visibility.php
[edit]
[+]
photon
[+]
seo-tools
[-] theme-tools.php
[edit]
[-] verification-tools.php
[edit]
[+]
gravatar
[+]
memberships
[+]
shortcodes
[+]
protect
[-] protect.php
[edit]
[+]
widget-visibility
[+]
cloudflare-analytics
[-] sso.php
[edit]
[-] google-analytics.php
[edit]
[+]
sharedaddy
[-] markdown.php
[edit]
[-] wpgroho.js
[edit]
[-] vaultpress.php
[edit]
[+]
geo-location
[+]
markdown
[+]
infinite-scroll
[-] photon.php
[edit]
[+]
wpcom-block-editor
[-] stats.php
[edit]
[-] copy-post.php
[edit]
[+]
related-posts
[-] related-posts.php
[edit]
[+]
custom-css
[+]
comment-likes
[+]
wpcom-tos
[-] wordads.php
[edit]
[+]
woocommerce-analytics
[+]
comments
[-] comments.php
[edit]
[+]
wordads
[+]
masterbar
[+]
sso
[+]
calypsoify
[-] likes.php
[edit]