src/Luminous/Formatters/LatexFormatter.php
public function defineStyleCommands()
    {
        if ($this->css === null) {
            throw new Exception('LaTeX formatter has not been set a theme');
        }
        $cmds = array();
        $round = function ($n) {
            return round($n, 2);
        };
        foreach ($this->css->rules() as $name => $properties) {
            if (!preg_match('/^\w+$/', $name)) {
                continue;
            }
            $cmd = "{#1}";
            if ($this->css->value($name, 'bold', false) === true) {
                $cmd = "{\\textbf$cmd}";
            }
            if ($this->css->value($name, 'italic', false) === true) {
                $cmd = "{\\emph$cmd}";
            }
            if (($col = $this->css->value($name, 'color', null)) !== null) {
                if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                    $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                    $rgb = array_map($round, $rgb);
                    $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                    $cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}";
                }
            }
            $name = str_replace('_', '', $name);
            $name = strtoupper($name);
            $cmds[] = "\\newcommand{\\lms{$name}}[1]$cmd";
        }

        if ($this->lineNumbers && ($col = $this->css->value('code', 'color', null)) !== null) {
            if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                $rgb = array_map($round, $rgb);
                $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                $cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}";
                $cmds[] = $cmd;
            }
        }
        return implode("\n", $cmds);
    }
public function defineStyleCommands()
    {
        if ($this->css === null) {
            throw new Exception('LaTeX formatter has not been set a theme');
        }
        $cmds = array();
        $round = function ($n) {
            return round($n, 2);
        };
        foreach ($this->css->rules() as $name => $properties) {
            if (!preg_match('/^\w+$/', $name)) {
                continue;
            }
            $cmd = "{#1}";
            if ($this->css->value($name, 'bold', false) === true) {
                $cmd = "{\\textbf$cmd}";
            }
            if ($this->css->value($name, 'italic', false) === true) {
                $cmd = "{\\emph$cmd}";
            }
            if (($col = $this->css->value($name, 'color', null)) !== null) {
                if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                    $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                    $rgb = array_map($round, $rgb);
                    $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                    $cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}";
                }
            }
            $name = str_replace('_', '', $name);
            $name = strtoupper($name);
            $cmds[] = "\\newcommand{\\lms{$name}}[1]$cmd";
        }

        if ($this->lineNumbers && ($col = $this->css->value('code', 'color', null)) !== null) {
            if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                $rgb = array_map($round, $rgb);
                $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                $cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}";
                $cmds[] = $cmd;
            }
        }
        return implode("\n", $cmds);
    }
public function defineStyleCommands ( ) { if ( $ this -> css === null ) { throw new Exception ( 'LaTeX formatter has not been set a theme' ) ; } $ cmds = array ( ) ; $ round = function ( $ n ) { return round ( $ n , 2 ) ; } ; foreach ( $ this -> css -> rules ( ) as $ name => $ properties ) { if ( ! preg_match ( '/^\w+$/' , $ name ) ) { continue ; } $ cmd = "{#1}" ; if ( $ this -> css -> value ( $ name , 'bold' , false ) === true ) { $ cmd = "{\\textbf$cmd}" ; } if ( $ this -> css -> value ( $ name , 'italic' , false ) === true ) { $ cmd = "{\\emph$cmd}" ; } if ( ( $ col = $ this -> css -> value ( $ name , 'color' , null ) ) !== null ) { if ( preg_match ( '/^#[a-f0-9]{6}$/i' , $ col ) ) { $ rgb = ColorUtils :: normalizeRgb ( ColorUtils :: hex2rgb ( $ col ) , true ) ; $ rgb = array_map ( $ round , $ rgb ) ; $ colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]" ; $ cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}" ; } } $ name = str_replace ( '_' , '' , $ name ) ; $ name = strtoupper ( $ name ) ; $ cmds [ ] = "\\newcommand{\\lms{$name}}[1]$cmd" ; } if ( $ this -> lineNumbers && ( $ col = $ this -> css -> value ( 'code' , 'color' , null ) ) !== null ) { if ( preg_match ( '/^#[a-f0-9]{6}$/i' , $ col ) ) { $ rgb = ColorUtils :: normalizeRgb ( ColorUtils :: hex2rgb ( $ col ) , true ) ; $ rgb = array_map ( $ round , $ rgb ) ; $ colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]" ; $ cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}" ; $ cmds [ ] = $ cmd ; } } return implode ( "\n" , $ cmds ) ; }
Defines all the styling commands, these are obtained from the css parser
Defines all the styling commands these are obtained from the css parser