GeSHi / geshi-1.0

Original version of Generic Syntax Highlighter for PHP
http://qbnz.com/highlighter/
GNU General Public License v2.0
168 stars 100 forks source link

improvement to latex highlighting code #132

Open tormec opened 4 years ago

tormec commented 4 years ago

Hello, this is my revision about how GeSHi highlights latex code. Refer to the "changes" section in the same script for what I've done. The image attached provides the final result (on the right) compared to the actual rendering. latex-geshi

tormec commented 4 years ago

The list of LaTex packages has been made with the following script

<?php
$tag = '<div class="dt"><a href="/pkg/';
$alphabet = array(
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
$packages = array();
foreach ($alphabet as $pg) {
    $content = file('https://ctan.org/pkg/:'.$pg);
    foreach ($content as $row) {
        $row = trim($row);
        if (strpos($row, $tag) !== false) {
            $packages[]= strstr(substr($row, strlen($tag)), '"', true);
        }
    }
}
$multi_str = '';
$str = '';
asort($packages);
foreach ($packages as $key => $val) {
    $str .= "'" . $val . "'" . ', ';
    if (strlen($str) >= 100 || $key == array_key_last($packages)) {
        $str .= '<br>';
        $multi_str .= $str;
        $str = '';
    }
}
echo $multi_str;

each keyword row spans 100 characters.