texlive[57190] trunk: pygmentex (21dec20)

commits+karl at tug.org commits+karl at tug.org
Mon Dec 21 23:09:05 CET 2020


Revision: 57190
          http://tug.org/svn/texlive?view=revision&revision=57190
Author:   karl
Date:     2020-12-21 23:09:04 +0100 (Mon, 21 Dec 2020)
Log Message:
-----------
pygmentex (21dec20)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/pygmentex/pygmentex.py
    trunk/Master/texmf-dist/scripts/pygmentex/pygmentex.py
    trunk/Master/texmf-dist/tex/latex/pygmentex/pygmentex.sty

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.c
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.delphi
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.hs
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.java
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pas
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.py
    trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.tex

Removed Paths:
-------------
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.c
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.delphi
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.hs
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.java
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pas
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pdf
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.py
    trunk/Master/texmf-dist/doc/latex/pygmentex/demo.tex

Modified: trunk/Build/source/texk/texlive/linked_scripts/pygmentex/pygmentex.py
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/pygmentex/pygmentex.py	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Build/source/texk/texlive/linked_scripts/pygmentex/pygmentex.py	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2
+#! /usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """
@@ -8,11 +8,11 @@
     PygmenTeX is a converter that do syntax highlighting of snippets of
     source code extracted from a LaTeX file.
 
-    :copyright: Copyright 2014 by José Romildo Malaquias
+    :copyright: Copyright 2020 by José Romildo Malaquias
     :license: BSD, see LICENSE for details
 """
 
-__version__ = '0.8'
+__version__ = '0.10'
 __docformat__ = 'restructuredtext'
 
 import sys
@@ -27,6 +27,7 @@
 from pygments.util import get_bool_opt, get_int_opt
 from pygments.lexer import Lexer
 from pygments.token import Token
+from pygments.util import guess_decode
 
 ###################################################
 # The following code is in >=pygments-2.0
@@ -56,17 +57,17 @@
             realoutfile = outfile
             outfile = StringIO()
 
-        outfile.write(u'\\begin{Verbatim}[commandchars=\\\\\\{\\}')
+        outfile.write(r'\begin{Verbatim}[commandchars=\\\{\}')
         if self.linenos:
             start, step = self.linenostart, self.linenostep
-            outfile.write(u',numbers=left' +
-                          (start and u',firstnumber=%d' % start or u'') +
-                          (step and u',stepnumber=%d' % step or u''))
+            outfile.write(',numbers=left' +
+                          (start and ',firstnumber=%d' % start or '') +
+                          (step and ',stepnumber=%d' % step or ''))
         if self.mathescape or self.texcomments or self.escapeinside:
-            outfile.write(u',codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}')
+            outfile.write(r',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
         if self.verboptions:
-            outfile.write(u',' + self.verboptions)
-        outfile.write(u']\n')
+            outfile.write(',' + self.verboptions)
+        outfile.write(']\n')
 
         for ttype, value in tokensource:
             if ttype in Token.Comment:
@@ -73,7 +74,7 @@
                 if self.texcomments:
                     # Try to guess comment starting lexeme and escape it ...
                     start = value[0:1]
-                    for i in xrange(1, len(value)):
+                    for i in range(1, len(value)):
                         if start[0] != value[i]:
                             break
                         start += value[i]
@@ -129,7 +130,7 @@
             else:
                 outfile.write(value)
 
-        outfile.write(u'\\end{Verbatim}\n')
+        outfile.write('\\end{Verbatim}\n')
 
         if self.full:
             realoutfile.write(DOC_TEMPLATE %
@@ -232,7 +233,7 @@
 '''
 
 
-def pyg(outfile, n, opts, extra_opts, text, usedstyles, inline_delim = ''):
+def pyg(outfile, outencoding, n, opts, extra_opts, text, usedstyles, inline_delim = ''):
     try:
         lexer = get_lexer_by_name(opts['lang'])
     except ClassNotFound as err:
@@ -260,27 +261,8 @@
     if tabsize:
         lexer.tabsize = tabsize
 
-    encoding = opts['encoding']
-    if encoding == 'guess':
-        try:
-            import chardet
-        except ImportError:
-            try:
-                text = text.decode('utf-8')
-                if text.startswith(u'\ufeff'):
-                    text = text[len(u'\ufeff'):]
-                    encoding = 'utf-8'
-            except UnicodeDecodeError:
-                text = text.decode('latin1')
-                encoding = 'latin1'
-        else:
-            encoding = chardet.detect(text)['encoding']
-            text = text.decode(encoding)
-    else:
-        text = text.decode(encoding)
-
     lexer.encoding = ''
-    _fmter.encoding = encoding
+    # _fmter.encoding = outencoding
 
     stylename = opts['sty']
 
@@ -367,7 +349,7 @@
     r'^<@@pygmented at input@(\d+)\n(.*)\n([\s\S]*?)\n>@@pygmented at input@\1$',
     re.MULTILINE)
 
-def convert(code, outfile):
+def convert(code, outfile, outencoding):
     """
     Convert ``code``
     """
@@ -393,6 +375,7 @@
         m = _re_inline.match(code, pos)
         if m:
             pyg(outfile,
+                outencoding,
                 m.group(1),
                 parse_opts(opts.copy(), m.group(2)),
                 '',
@@ -405,6 +388,7 @@
         m = _re_display.match(code, pos)
         if m:
             pyg(outfile,
+                outencoding,
                 m.group(1),
                 parse_opts(opts.copy(), m.group(2)),
                 '',
@@ -415,15 +399,16 @@
 
         m = _re_input.match(code, pos)
         if m:
+            opts_new = parse_opts(opts, m.group(2))
             try:
-                filecontents = open(m.group(3), 'rb').read()
+                filecontents, inencoding = read_input(m.group(3), opts_new['encoding'])
             except Exception as err:
-                sys.stderr.write('Error: cannot read input file: ')
-                sys.stderr.write(str(err))
+                print('Error: cannot read input file: ', err, file=sys.stderr)
             else:
                 pyg(outfile,
+                    outencoding,
                     m.group(1),
-                    parse_opts(opts, m.group(2)),
+                    opts_new,
                     "",
                     filecontents,
                     usedstyles)
@@ -435,8 +420,18 @@
 
     outfile.write(GENERIC_DEFINITIONS_2)
 
+def read_input(filename, encoding):
+    with open(filename, 'rb') as infp:
+        code = infp.read()
 
+    if not encoding or encoding == 'guess':
+        code, encoding = guess_decode(code)
+    else:
+        code = code.decode(encoding)
 
+    return code, encoding
+
+
 USAGE = """\
 Usage: %s [-o <output file name>] <input file name>
        %s -h | -V
@@ -486,7 +481,7 @@
         return 0
 
     if opts.pop('-V', None) is not None:
-        print('PygmenTeX version %s, (c) 2010 by José Romildo.' % __version__)
+        print('PygmenTeX version %s, (c) 2020 by José Romildo.' % __version__)
         return 0
  
     if len(args) != 1:
@@ -494,10 +489,9 @@
         return 2
     infn = args[0]
     try:
-        code = open(infn, 'rb').read()
+        code, inencoding = read_input(infn, "guess")
     except Exception as err:
-        sys.stderr.write('Error: cannot read input file: ')
-        sys.stderr.write(str(err))
+        print('Error: cannot read input file: ', err, file=sys.stderr)
         return 1
 
     outfn = opts.pop('-o', None)
@@ -507,11 +501,10 @@
     try:
         outfile = open(outfn, 'w')
     except Exception as err:
-        sys.stderr.write('Error: cannot open output file: ')
-        sys.stderr.write(str(err))
+        print('Error: cannot open output file: ', err, file=sys.stderr)
         return 1
 
-    convert(code, outfile)
+    convert(code, outfile, inencoding)
 
     return 0
 

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.c
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.c	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.c	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,22 +0,0 @@
-// test.cpp
-
-#include <iostream>
-
-using namespace std;
-
-void greetings()
-{
-   string name;
-   cout << "What is your name? ";
-   cin >> name;
-   cout << "Hello, "
-	<< name
-	<< '!'
-	<< endl;
-}
-
-int main()
-{
-   greetings();
-   return 0;
-}

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.delphi
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.delphi	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.delphi	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,8 +0,0 @@
-procedure example(a: integer);
-const
-  A = 'jeja';
-var
-  sMessage: string;
-begin
-  ShowMessage(sMessage + A);
-end;

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.hs
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.hs	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.hs	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,7 +0,0 @@
-module Main where
-
--- the main IO action
-main = do { putStr "What is your name? "
-          , name''' <- read
-          , putStrLn ("Hello, " ++ name''')
-          }

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.java
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.java	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.java	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,68 +0,0 @@
-import java.io.IOException;
-import java.io.Reader;
-import java.util.Hashtable;
-import java.util.Map;
-
-public class Lexer
-{
-   private Reader in;
-   private int x;
-   
-   private Map<String,Token.T> reserved =
-      new Hashtable<String,Token.T>();
-   
-   public Lexer(Reader in) throws IOException
-   {
-      this.in = in;
-      x = in.read();
-      reserved.put("let", Token.T.LET);
-      // acrescentar demais palavras reservadas
-      // ...
-   }
-
-   public Token get() throws IOException
-   {
-      // retornar o próximo símbolo léxico do programa
-      
-      while (Character.isWhitespace(x))
-         x = in.read();
-
-      if (x == -1)
-         return new Token(Token.T.EOF);
-      
-      if ((char)x == ',')
-      {
-         x = in.read();
-         return new Token(Token.T.COMMA);
-      }
-
-      if (Character.isDigit(x))
-      {
-         StringBuilder builder = new StringBuilder();
-         builder.append((char)x);
-         while (Character.isDigit((x = in.read())))
-            builder.append((char)x);
-         return new Token(Token.T.INT, new Long(builder.toString()));
-      }
-
-      if (Character.isAlphabetic(x))
-      {
-         StringBuilder builder = new StringBuilder();
-         builder.append((char)x);
-         while (Character.isAlphabetic(x = in.read()) ||
-                Character.isDigit(x) || (char)x == '_')
-            builder.append((char)x);
-         String s = builder.toString();
-         Token.T t = reserved.get(s);
-         if (t == null)
-            return new Token(Token.T.ID, s);
-         return new Token(t);
-      }
-
-      // completar demais tokens
-      
-      System.out.println("unexpectec char: <" + (char)x + ">");
-      x = in.read();
-      return get();
-   }
-}

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pas
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pas	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pas	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,7 +0,0 @@
-Program HelloWorld(output)
-var
-   msg : String
-begin
-   msg = 'Hello, world!';
-   Writeln(msg)
-end.

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.pdf
===================================================================
(Binary files differ)

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.py
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.py	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.py	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-
-def parse_opts(dic, opts):
-    for opt in re.split(r'\s*,\s*', opts):
-        x = re.split(r'\s*=\s*', opt)
-        if len(x) == 2 and x[0] and x[1]:
-            dic[x[0]] = x[1]
-        elif len(x) == 1 and x[0]:
-            dic[x[0]] = True
-    return dic

Deleted: trunk/Master/texmf-dist/doc/latex/pygmentex/demo.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/demo.tex	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/demo.tex	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,852 +0,0 @@
-\documentclass[10pt,a4paper]{article}
-
-%\usepackage[margin=13mm]{geometry}
-\usepackage[utf8]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage[font=normalsize,format=plain,labelfont=bf,up,textfont=it,up]{caption}
-\usepackage{xcolor}
-\usepackage{hyperref}
-\usepackage[framemethod=tikz]{mdframed}
-\usepackage{tcolorbox}
-\usepackage{fvrb-ex}
-\usepackage{tikz}
-\usepackage{calc}
-\usepackage{pygmentex}
-\usepackage{lipsum}
-
-\fvset{gobble=0,showtabs,tabsize=1,frame=lines,framerule=1pt,numbers=left,fontsize=\scriptsize}
-
-\tcbuselibrary{skins,breakable}
-
-\definecolor{shadecolor}{rgb}{0.9,0.9,0.9}
-\definecolor{lightgreen}{rgb}{0.8,0.95,0.8}
-
-\begin{document}
-
-\title{Testing the Pygmen\TeX{} package}
-\author{José Romildo Malaquias}
-\maketitle
-
-\section{The Pygmen\TeX{} package}
-
-This document demonstrates how to use the Pygment\TeX{} package to
-typeset code listings with \LaTeX{} and
-Pygments\footnote{\url{http://pygments.org/}}.
-
-Pygments is a generic syntax highlighter for general use in all kinds of
-software such as forum systems, wikis or other applications that need to
-prettify source code.
-
-Pygmen\TeX{} provides an environment and two commands for typesetting code
-listings in a \LaTeX{} document:
-\begin{itemize}
-  \item the \verb|pygmented| environment typesets its contents as a
-  source code listing,
-  \item the \verb|includepygmented| command typesets the contents of a
-  file, including the result in the \LaTeX{} document, and
-  \item the \verb|\pyginline| command typesets its contents, keeping the
-  result in the same line.
-\end{itemize}
-They accept many options that allow the user to configure the listing in
-many ways.
-
-Read the remaining of this document to have an idea of what the package
-is capable of.
-
-\section{How to use the package}
-
-In order to use the package, start by putting
-\begin{verbatim}
-\usepackage{pygmentex}
-\end{verbatim}
-in the preamble of the document.
-
-Use the environment or commands mentioned previously to include source
-code listings on your document.
-
-When compiling the document (with \texttt{pdflatex}, for instance), all
-the source code listings in the document wil be collected and saved in a
-temporary file with the extension \texttt{.snippets} in its name. Then
-the auxiliary program \texttt{pygmentex} (a Python application
-distributed with the Pygmen\TeX{} package) should be run taking this
-file as input. It will produce another temporary file with the extension
-\texttt{.pygmented}, containing \LaTeX{} code for the code listings
-previously collected. The next time the document is compiled, they are
-included to produce the final typeset document.
-
-The programming language of the listing code can be specified using the
-\verb|lang| option.
-
-To get a list of all available languages, execute the following command
-on the command line:
-\begin{verbatim}
-$ pygmentize -L lexers
-\end{verbatim}
-
-\section{First examples}
-
-The followig C program reads two integers and calculates their sum.
-
-\begin{Example}
-\begin{pygmented}[lang=c]
-#include <stdio.h>
-int main(void)
-{
-   int a, b, c;
-   printf("Enter two numbers to add: ");
-   scanf("%d%d", &a, &b);
-   c = a + b;
-   printf("Sum of entered numbers = %d\n", c);
-   return 0;
-}
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-  In this program, \pyginline[lang=c]|int| is a type and
-  \pyginline[lang=c]|"Enter two numbers to add: "| is a literal string.
-\end{Example}
-
-Next you can see a Java program to calculate the factorial of a number.
-
-\begin{Example}
-\inputpygmented[lang=java]{Factorial.java}
-\end{Example}
-
-\section{Choosing different Pygments styles}
-
-Instead of using the default style you may choose another stylesheet
-provided by Pygments by its name using the \verb|sty| option.
-
-To get a list of all available stylesheets, execute the following
-command on the command line:
-\begin{verbatim}
-$ pygmentize -L styles
-\end{verbatim}
-
-Creating your own styles is also very easy. Just follow the instructions
-provided on the website.
-
-As examples you can see a C program typeset with different styles.
-
-\begin{Example}
-\noindent
-\begin{minipage}[t]{0.49\linewidth}
-  \begin{pygmented}[lang=c,gobble=4,sty=murphy]
-    #include<stdio.h> 
-    main()
-    { int n;
-      printf("Enter a number: ");
-      scanf("%d",&n);
-      if ( n%2 == 0 )
-         printf("Even\n");
-      else
-         printf("Odd\n");
-      return 0;
-    }
-  \end{pygmented}
-\end{minipage}
-\hfil
-\begin{minipage}[t]{0.49\linewidth}
-  \begin{pygmented}[lang=c,gobble=4,sty=trac]
-    #include<stdio.h> 
-    main()
-    { int n;
-      printf("Enter a number: ");
-      scanf("%d",&n);
-      if ( n%2 == 0 )
-         printf("Even\n");
-      else
-         printf("Odd\n");
-      return 0;
-    }
-  \end{pygmented}
-\end{minipage}
-\end{Example}
-
-\section{Choosing a font}
-
-The value of the option \verb|font| is typeset before the content of the
-listing. Usualy it is used to specify a font to be used. See the
-following example.
-
-\begin{Example}
-\begin{pygmented}[lang=scala,font=\rmfamily\scshape\large]
-object bigint extends Application {
-  def factorial(n: BigInt): BigInt =
-    if (n == 0) 1 else n * factorial(n-1)
-
-  val f50 = factorial(50); val f49 = factorial(49)
-  println("50! = " + f50)
-  println("49! = " + f49)
-  println("50!/49! = " + (f50 / f49))
-}
-\end{pygmented}
-\end{Example}
-
-\section{Changing the background color}
-
-The option \verb|colback| can be used to choose a background color, as
-is shown in the folowing example.
-
-\begin{Example}
-\begin{pygmented}[lang=fsharp,colback=green!25]
-let rec factorial n = 
-    if n = 0 
-    then 1 
-    else n * factorial (n - 1)
-System.Console.WriteLine(factorial anInt)
-\end{pygmented}
-\end{Example}
-
-
-\section{Supressing initial characters}
-
-The option \verb|gobble| specifies the number of characters to suppress
-at the beginning of each line (up to a maximum of 9). This is mainly
-useful when environments are indented (Default: empty — no character
-suppressed).
-
-\begin{Example}
-A code snippet inside a minipage:
-\begin{minipage}[t]{.5\linewidth}
-    \begin{pygmented}[lang=d,gobble=8]
-        ulong fact(ulong n)
-        {
-          if(n < 2)
-            return 1;
-          else
-            return n * fact(n - 1);
-        }
-      \end{pygmented}
-\end{minipage}
-\end{Example}
-
-
-\section{Size of tabulator}
-
-The option \verb|tabsize| specifies the number of of spaces given by a
-tab character (Default: 8).
-
-\begin{Verbatim}[showtabs,tabsize=1]
-\begin{pygmented}[lang=common-lisp,tabsize=4]
-;; Triple the value of a number
-(defun triple	(X)
-	"Compute three times X."
-	(* 3 X))
-\end{pygmented}
-\end{Verbatim}
-
-\begin{pygmented}[lang=common-lisp,tabsize=4]
-;; Triple the value of a number
-(defun triple	(X)
-	"Compute three times X."
-	(* 3 X))
-\end{pygmented}
-
-
-\section{Numbering lines}
-
-The lines of a listing can be numbered. The followig options control
-numbering of lines.
-\begin{itemize}
-  \item Line numbering is enabled or disable with the \verb|linenos|
-  boolean option.
-  \item The number used for the first line can be set with the option
-  \verb|linenostart|.
-  \item The step between numbered lines can be set with the option
-  \verb|linenostep|.
-  \item The space between the line number and the line of the listing
-  can be set with the option \verb|linenosep|.
-\end{itemize}
-
-In the followig listing you can see a Scheme function to calculate the
-factorial of a number.
-
-\begin{Example}
-\begin{pygmented}[lang=scheme,linenos,linenostart=1001,linenostep=2,linenosep=5mm]
-;; Building a list of squares from 0 to 9.
-;; Note: loop is simply an arbitrary symbol used as
-;; a label. Any symbol will do.
- 
-(define (list-of-squares n)
-  (let loop ((i n) (res '()))
-    (if (< i 0)
-        res
-        (loop (- i 1) (cons (* i i) res)))))
-\end{pygmented}
-\end{Example}
-
-\section{Captioning}
-
-The option \verb|caption| can be used to set a caption for the listing.
-The option \verb|label| allows the assignment of a label to the listing.
-
-Here is an example:
-
-\begin{Example}
-\begin{pygmented}[lang=c++,label=lst:test,caption=A \textbf{C++} example]
-// This program adds two numbers and prints their sum.
-#include <iostream>
-int main()
-{
-  int a;
-  int b;
-  int sum;
-  sum = a + b;
-  std::cout << "The sum of " << a << " and " << b
-            << " is " << sum << "\n";
-  return 0;
-}
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-  Listing \ref{lst:test} is a C++ program.
-\end{Example}
-
-\section{Escaping to \LaTeX{} inside a code snippet}
-
-The option \verb|texcomments|, if set to \texttt{true}, enables \LaTeX{}
-comment lines. That is, LaTex markup in comment tokens is not escaped
-so that \LaTeX{} can render it.
-
-The \verb|mathescape|, if set to \texttt{true}, enables \LaTeX{} math
-mode escape in comments. That is, \verb|$...$| inside a comment will
-trigger math mode.
-
-The option \verb|escapeinside|, if set to a string of length two,
-enables escaping to \LaTeX{}. Text delimited by these two characters
-is read as \LaTeX{} code and typeset accordingly. It has no effect in
-string literals. It has no effect in comments if \verb|texcomments| or
-\verb|mathescape| is set.
-
-Some examples follows.
-
-\begin{Example}
-\begin{pygmented}[lang=c++,texcomments]
-#include <iostream>
-using namespace std;
-main()
-{
-   cout << "Hello World";  // prints \underline{Hello World}
-   return 0;
-}
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\begin{pygmented}[lang=python,mathescape]
-# Returns $\sum_{i=1}^{n}i$
-def sum_from_one_to(n):
-    r = range(1, n + 1)
-    return sum(r)
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\begin{pygmented}[lang=c,escapeinside=||]
-
-if (|\textit{condition}|)
-    |\textit{command$_1$}|
-else
-    |\textit{command$_2$}|
-\end{pygmented}
-\end{Example}
-
-
-\section{Enclosing command and environment}
-
-After being prettified by Pygments, the listings are enclosed in a
-command (for \verb|\pyginline|) or in an environment (for
-\verb|pygmented| and \verb|includepygmented|). By default
-\verb|\pyginline| uses the command \verb|\efbox| from the \texttt{efbox}
-package, and \verb|pygmented| and \verb|includepygmented| use the
-environment \verb|mdframed| from the \texttt{mdframed} package.
-
-The enclosing command or environment should be configurable using a list
-of key-value pairs written between square brackets.
-
-The enclosing command for
-\verb|\pyginline| can be changed with the option
-\verb|inline method|. For instance, in the following the command
-\verb|\tcbox| from the \verb|tcolorbox| package is used:
-
-\begin{Example}
-  In the previous Java program,
-  \pyginline[lang=java,inline method=tcbox]|"Factorial of "| is a
-  literal string.
-\end{Example}
-
-The enclosing environment for \verb|pygmented| and
-\verb|includepygmented| can be changed with the option
-\verb|boxing method|. For instance, here is a hello world program in
-C\#, enclosed in a \verb|tcolorbox| environment:
-
-\begin{Example}
-\begin{pygmented}[lang=csharp,boxing method=tcolorbox]
-using System;
-class Program
-{
-    public static void Main(string[] args)
-    {
-        Console.WriteLine("Hello, world!");
-    }
-}
-\end{pygmented}
-\end{Example}
-
-Any option unknown to Pygmen\TeX{} are passed to the enclosing command
-or environment.
-
-For instance:
-
-\begin{Example}
-\begin{pygmented}[lang=xml,boxing method=tcolorbox,colframe=red,boxrule=2mm]
-<!-- This is a note -->
-<note>
-   <to>Tove</to>
-   <from>Jani</from>
-   <heading>Reminder</heading>
-   <body>Don't forget me this weekend!</body>
-</note>
-\end{pygmented}
-\end{Example}
-
-\section{Setting global options for Pygmen\TeX{}}
-
-Global options can be setting using the \verb|setpygmented| command.
-See the examples that follows.
-
-\begin{Example}
-\setpygmented{lang=haskell, colback=red!30, font=\ttfamily\small}
-
-\begin{pygmented}[]
-sum :: Num a => [a] -> a
-sum [] = 0
-sum (x:xs) = x + sum xs
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\begin{pygmented}[colback=blue!20, boxing method=tcolorbox]
-elem :: Eq a => a -> [a] -> Bool
-elem _ [] = False
-elem x (y:ys) = x == y || elem x ys
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\setpygmented{lang=snobol}
-
-\begin{pygmented}[]
-          OUTPUT = "What is your name?"
-          Username = INPUT
-          OUTPUT = "Thank you, " Username
-END
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\setpygmented{test/.style={colback=yellow!33,boxing method=tcolorbox,colframe=blue}}
-
-\begin{pygmented}[test, lang=vbnet]
-Module Module1
-    Sub Main() 
-        Console.WriteLine("Hello, world!")
-    End Sub
-End Module
-\end{pygmented}
-\end{Example}
-
-\begin{Example}
-\begin{pygmented}[lang=tcl]
-puts "Hello, world!"
-\end{pygmented}
-\end{Example}
-
-\section{More examples of inline code snippets}
-
-\begin{Example}
-  An inline source code snippet:
-  \pyginline[lang=c]|const double alfa = 3.14159;|.
-  This is a C declaration with initialization.
-\end{Example}
-
-\begin{Example}
-  \pyginline[lang=prolog,colback=yellow]=avo(A,B) :- pai(A,X), pai(X,B).=
-  is a Prolog clause. Its head is
-  \pyginline[lang=prolog,sty=emacs,colback=yellow,linecolor=red]=avo(A,B)=
-  and its body is
-  \pyginline[lang=prolog,sty=vim,colback=black,hidealllines]=pai(A,X), pai(X,B)=.
-\end{Example}
-
-\begin{Example}
-  See the identifier \pyginline[inline method=efbox,colback=green!25]|variable|,
-  which names something. String literals in C looks like
-  \pyginline[lang=c,inline method=tcbox,colback=blue!20,boxrule=2pt]|"hello, world!\n"|.
-\end{Example}
-
-\setpygmented{colback=shadecolor}
-
-\begin{Example}
-  This one
-  \pyginline[lang=ocaml,font=\ttfamily\scriptsize,topline=false]:let x = [1;2;3] in length x:
-  is an OCaml expression with local bindings. With OCaml one can do
-  imperative, functional and object oriented programming.
-\end{Example}
-
-\begin{Example}
-  Now some Java code:
-  \pyginline[lang=java,sty=colorful,font=\ttfamily\itshape,linewidth=1pt]|public int f(double x)|.
-  This is a method header.
-\end{Example}
-
-\section{More examples of displayed code snippets}
-
-\setpygmented{lang=scheme,colback=shadecolor,sty=emacs}
-
-In listing \ref{lst:fact} you can see a function definition in the
-Scheme language. This function computes the factorial of a natural
-number.
-\newline\rule{\linewidth}{2pt}
-\begin{pygmented}[
-  sty=emacs,
-  linenos,
-  label=lst:fact,
-  caption=A Scheme function.
-  ]
-(define fact
-    (lambda (n)
-        (if (= n 0)
-            1
-            (* n (fact (- n 1))))))
-\end{pygmented}
-
-Here you have some more code to further testing the package. Listing
-\ref{lst:haskell} is a Haskell program. When run this program interacts
-with the user asking the user name, reading a line input by the user,
-and showing a greeting message to the user.
-
-\inputpygmented[%
-  lang=haskell,
-  linenos,
-  linenostart=79831,
-  innerlinecolor=yellow, innerlinewidth=6pt,
-  middlelinecolor=blue, middlelinewidth=10pt,
-  outerlinecolor=green, outerlinewidth=12pt,
-  roundcorner=4,
-  colback=shadecolor,
-  caption=A haskell interactive program,
-  label=lst:haskell,
-  ]{demo.hs}
-
-This is a rule:
-
-\noindent\rule{\linewidth}{2pt}
-
-Now a Pascal procedure:
-
-\inputpygmented[
-  lang=delphi,
-  linewidth=1.5pt,
-  font=\ttfamily\sffamily\large,
-  colback=yellow
-  ]{demo.delphi}
-and a Pascal program
-\inputpygmented[lang=pascal,linenos,linenostart=5801]{demo.pas}
-
-A Python code snippet:
-
-\inputpygmented[
-  lang=python,
-  sty=emacs,
-  linenos,
-  linenostep=3,
-  linewidth=1pt,
-  colback=lightgreen
-  ]{demo.py}
-
-\section{Using code snippets in environments}
-
-The following is a \textbf{description} environment.
-
-\begin{description}
-  \item[An item] \lipsum[31]
-  \begin{pygmented}[lang=scala,colback=yellow,
-    % title=Item A
-    ]
-def qsort(xs: List[Int]): List[Int] =
-  xs match {
-    case Nil =>
-      Nil
-    case pivot :: tail =>
-      qsort(tail filter { _ < pivot }) :::
-        pivot :: qsort(tail filter { _ >= pivot })
-  }
-  \end{pygmented}
-  \lipsum[32]
-  
-  \item[Another item] \lipsum[33]
-  \begin{pygmented}[lang=lua,colback=yellow]
-function entry0 (o)
-  N=N + 1
-  local title = o.title or '(no title)'
-  fwrite('<LI><A HREF="#%d">%s</A>\n', N, title)
-end
-  \end{pygmented}
-  \lipsum[34]
-\end{description}
-
-\section{A long program}
-
-Here you can read the source code for a hand written lexical analyser
-for the \emph{straight-line} programming language that I have developed
-in Java.
-
-\inputpygmented[boxing method=mdframed,lang=java,sty=autumn,colback=red!8,font=\ttfamily\small,tabsize=2,frametitle=\emph{Ad hoc} lexical analyser]{demo.java}
-
-\section{Some fancy examples using \texttt{tcolorbox}}
-
-The followig example uses \texttt{tcolorbox} to typeset the code
-listing.
-
-\newcounter{example}
-\newlength{\examlen}
-\colorlet{colexam}{red!75!black}
-
-\begin{pygmented}[boxing method=tcolorbox,lang=scala,
-  title=Example \arabic{example}: hello from \texttt{Scala},
-  code={\refstepcounter{example}%
-        \settowidth{\examlen}{\Large\bfseries Example \arabic{example}}},%
-  coltitle=colexam,fonttitle=\Large\bfseries,
-  enhanced,breakable,
-  before=\par\medskip,
-  parbox=false,
-  frame hidden,interior hidden,segmentation hidden,
-  boxsep=0pt,left=0pt,right=3mm,toptitle=2mm,pad at break=0mm,
-  overlay unbroken={\draw[colexam,line width=1pt] (frame.north west)
-    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east)
-    --(frame.south west);
-    \draw[colexam,line width=2pt] ([yshift=0.5pt]frame.north west)
-    -- +(\examlen,0pt);},
-  overlay first={\draw[colexam,line width=1pt] (frame.north west)
-    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east);
-    \draw[red!75!black,line width=2pt] ([yshift=0.5pt]frame.north west)
-    -- +(\examlen,0pt);},
-  overlay middle={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
-    --([xshift=-0.5pt]frame.south east); },
-  overlay last={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
-    --([xshift=-0.5pt]frame.south east)--(frame.south west);}%
-  ]
-object HelloWorld extends App {
-  println("Hello, world!")
-}\end{pygmented}
-
-\begin{pygmented}[boxing method=tcolorbox,lang=java,
-  enhanced,colback=blue!10!white,colframe=orange,top=4mm,
-  enlarge top by=\baselineskip/2+1mm,
-  enlarge top at break by=0mm,pad at break=2mm,
-  fontupper=\normalsize,
-  overlay unbroken and first={%
-    \node[rectangle,rounded corners,draw=black,fill=blue!20!white,
-    inner sep=1mm,anchor=west,font=\small]
-    at ([xshift=4.5mm]frame.north west) {\strut\textbf{My fancy title}};},
-  ]
-public class Hello {
-  public static void main(String[] args) {
-    System.out.println("Hello, world!")
-  }
-}
-\end{pygmented}
-
-\begin{pygmented}[boxing method=tcolorbox,lang=haskell,
-  enhanced,sharp corners=uphill,
-  colback=blue!25!white,colframe=blue!25!black,coltext=blue!90!black,
-  fontupper=\Large\bfseries,arc=6mm,boxrule=2mm,boxsep=5mm,
-  borderline={0.3mm}{0.3mm}{white}
-  ]
-module Main (main) where
-
-main :: IO ()
-main = putStrLn "Hello, world!"
-\end{pygmented}
-
-\begin{pygmented}[boxing method=tcolorbox,lang=c++,
-  enhanced,frame style image=blueshade.png,
-  opacityback=0.75,opacitybacktitle=0.25,
-  colback=blue!5!white,colframe=blue!75!black,
-  title=My title
-  ]
-#include <iostream>
-using namespace std;
-int main(int argc, char** argv) {
-  cout << "Hello, world!" << endl;
-  return 0;
-}
-\end{pygmented}
-
-\begin{pygmented}[boxing method=tcolorbox,lang=d,
-  enhanced,attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},
-  colback=blue!5!white,colframe=blue!75!black,colbacktitle=red!80!black,
-  title=My title,fonttitle=\bfseries,
-  boxed title style={size=small,colframe=red!50!black}
-  ]
-/* This program prints a
-   hello world message
-   to the console.  */
- 
-import std.stdio;
- 
-void main()
-{
-    writeln("Hello, World!");
-}
-\end{pygmented}
-
-
-\section{Some fancy examples using \texttt{mdframed}}
-
-The followig example uses \texttt{mdframed} to typeset the code listing.
-
-\global\mdfdefinestyle{exampledefault}{%
-  linecolor=red,linewidth=3pt,%
-  leftmargin=1cm,rightmargin=1cm
-}
-
-\begin{pygmented}[boxing method=mdframed,lang=ada,style=exampledefault]
-with Ada.Text_IO;
- 
-procedure Hello_World is
- use Ada.Text_IO;
-begin
-    Put_Line("Hello, world!");
-end;
-\end{pygmented}
-
-\global\mdfapptodefinestyle{exampledefault}{%
-  topline=false,bottomline=false,
-}
-
-\begin{pygmented}[boxing method=mdframed,lang=pascal,style=exampledefault,frametitle={Saying \emph{hello} from Pascal}]
-program HelloWorld;
- 
-begin
-  WriteLn('Hello, world!');
-end.
-\end{pygmented}
-
-\global\mdfdefinestyle{separateheader}{%
-  frametitle={%
-    \tikz[baseline=(current bounding box.east),outer sep=0pt]
-    \node[anchor=east,rectangle,fill=blue!20]
-    {\strut Saying \emph{hello} in Modula-2};},
-  innertopmargin=10pt,linecolor=blue!20,%
-  linewidth=2pt,topline=true,
-  frametitleaboveskip=\dimexpr-\ht\strutbox\relax,
-  frametitlerule=false,
-  backgroundcolor=white,
-}
-
-\begin{pygmented}[boxing method=mdframed,lang=modula2,style=separateheader]
-MODULE Hello;
-FROM STextIO IMPORT WriteString;
-BEGIN
-  WriteString("Hello World!");
-END Hello.
-\end{pygmented}
-
-
-\tikzset{titregris/.style =
-     {draw=gray, thick, fill=white, shading = exersicetitle, %
-      text=gray, rectangle, rounded corners, right,minimum height=.7cm}}
-\pgfdeclarehorizontalshading{exersicebackground}{100bp}
-          {color(0bp)=(green!40); color(100bp)=(black!5)}
-\pgfdeclarehorizontalshading{exersicetitle}{100bp}
-          {color(0bp)=(red!40);color(100bp)=(black!5)}
-\newcounter{exercise}
-\renewcommand*\theexercise{Exercise~n\arabic{exercise}}
-\makeatletter
-\def\mdf@@exercisepoints{}%new mdframed key:
-\define at key{mdf}{exercisepoints}{%
-    \def\mdf@@exercisepoints{#1}
-}
-\mdfdefinestyle{exercisestyle}{%
-  outerlinewidth=1em,outerlinecolor=white,%
-  leftmargin=-1em,rightmargin=-1em,%
-  middlelinewidth=1.2pt,roundcorner=5pt,linecolor=gray,
-  apptotikzsetting={\tikzset{mdfbackground/.append style ={%
-                       shading = exersicebackground}}},
-  innertopmargin=1.2\baselineskip,
-  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
-  skipbelow={-1em},
-  needspace=3\baselineskip,
-  frametitlefont=\sffamily\bfseries,
-  settings={\global\stepcounter{exercise}},
-  singleextra={%
-      \node[titregris,xshift=1cm] at (P-|O) %
-         {~\mdf at frametitlefont{\theexercise}\hbox{~}};
-      \ifdefempty{\mdf@@exercisepoints}%
-      {}%
-      {\node[titregris,left,xshift=-1cm] at (P)%
-        {~\mdf at frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
-   },
-  firstextra={%
-      \node[titregris,xshift=1cm] at (P-|O) %
-         {~\mdf at frametitlefont{\theexercise}\hbox{~}};
-      \ifdefempty{\mdf@@exercisepoints}%
-      {}%
-      {\node[titregris,left,xshift=-1cm] at (P)%
-        {~\mdf at frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
-   },
-}
-\makeatother
-
-\begin{pygmented}[boxing method=mdframed,lang=go,style=exercisestyle]
-// hello world in 'go'
-package main
- 
-import "fmt"
- 
-func main() {
-   fmt.Println("Hello, world!")
-}
-\end{pygmented}
-
-\begin{pygmented}[boxing method=mdframed,lang=objective-c,style=exercisestyle,exercisepoints=10]
-/* hello from objective-c */
-
-#import <stdio.h>
-#import <Foundation/Foundation.h>
- 
-int main(void)
-{
-    NSLog(@"Hello, world!\n");
-    return 0;
-}
-\end{pygmented}
-
-\mdfdefinestyle{another}{%
-  linecolor=red,middlelinewidth=2pt,%
-  frametitlerule=true,%
-  apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
-        shade,left color=white, right color=blue!20}}},
-  frametitlerulecolor=green!60,
-  frametitlerulewidth=1pt,
-  innertopmargin=\topskip,
-}
-
-\begin{pygmented}[boxing method=mdframed,lang=c,style=another,frametitle={Hello from C}]
-#include <stdio.h>
-int main(int argc, char **argv) {
-  printf("Hello, world!\n");
-  return 0;
-}
-\end{pygmented}
-
-
-\section{Conclusion}
-
-That is all.
-
-\end{document}

Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.c
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.c	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.c	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,22 @@
+// test.cpp
+
+#include <iostream>
+
+using namespace std;
+
+void greetings()
+{
+   string name;
+   cout << "What is your name? ";
+   cin >> name;
+   cout << "Hello, "
+	<< name
+	<< '!'
+	<< endl;
+}
+
+int main()
+{
+   greetings();
+   return 0;
+}


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.delphi
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.delphi	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.delphi	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,8 @@
+procedure example(a: integer);
+const
+  A = 'jeja';
+var
+  sMessage: string;
+begin
+  ShowMessage(sMessage + A);
+end;

Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.hs
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.hs	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.hs	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,7 @@
+module Main where
+
+-- the main IO action
+main = do { putStr "What is your name? "
+          , name''' <- read
+          , putStrLn ("Hello, " ++ name''')
+          }


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.hs
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.java
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.java	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.java	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,68 @@
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class Lexer
+{
+   private Reader in;
+   private int x;
+   
+   private Map<String,Token.T> reserved =
+      new Hashtable<String,Token.T>();
+   
+   public Lexer(Reader in) throws IOException
+   {
+      this.in = in;
+      x = in.read();
+      reserved.put("let", Token.T.LET);
+      // acrescentar demais palavras reservadas
+      // ...
+   }
+
+   public Token get() throws IOException
+   {
+      // retornar o próximo símbolo léxico do programa
+      
+      while (Character.isWhitespace(x))
+         x = in.read();
+
+      if (x == -1)
+         return new Token(Token.T.EOF);
+      
+      if ((char)x == ',')
+      {
+         x = in.read();
+         return new Token(Token.T.COMMA);
+      }
+
+      if (Character.isDigit(x))
+      {
+         StringBuilder builder = new StringBuilder();
+         builder.append((char)x);
+         while (Character.isDigit((x = in.read())))
+            builder.append((char)x);
+         return new Token(Token.T.INT, new Long(builder.toString()));
+      }
+
+      if (Character.isAlphabetic(x))
+      {
+         StringBuilder builder = new StringBuilder();
+         builder.append((char)x);
+         while (Character.isAlphabetic(x = in.read()) ||
+                Character.isDigit(x) || (char)x == '_')
+            builder.append((char)x);
+         String s = builder.toString();
+         Token.T t = reserved.get(s);
+         if (t == null)
+            return new Token(Token.T.ID, s);
+         return new Token(t);
+      }
+
+      // completar demais tokens
+      
+      System.out.println("unexpectec char: <" + (char)x + ">");
+      x = in.read();
+      return get();
+   }
+}


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pas
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pas	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pas	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,7 @@
+Program HelloWorld(output)
+var
+   msg : String
+begin
+   msg = 'Hello, world!';
+   Writeln(msg)
+end.


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pas
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf	2020-12-21 22:09:04 UTC (rev 57190)

Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.py
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.py	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.py	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+
+def parse_opts(dic, opts):
+    for opt in re.split(r'\s*,\s*', opts):
+        x = re.split(r'\s*=\s*', opt)
+        if len(x) == 2 and x[0] and x[1]:
+            dic[x[0]] = x[1]
+        elif len(x) == 1 and x[0]:
+            dic[x[0]] = True
+    return dic


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.tex	2020-12-21 22:09:04 UTC (rev 57190)
@@ -0,0 +1,861 @@
+\documentclass[10pt,a4paper]{article}
+
+%\usepackage[margin=13mm]{geometry}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage[font=normalsize,format=plain,labelfont=bf,up,textfont=it,up]{caption}
+\usepackage{xcolor}
+\usepackage{hyperref}
+\usepackage[framemethod=tikz]{mdframed}
+\usepackage{tcolorbox}
+\usepackage{fancyvrb-ex}
+\usepackage{tikz}
+\usepackage{calc}
+\usepackage{pygmentex}
+\usepackage{lipsum}
+
+\fvset{gobble=0,showtabs,tabsize=1,frame=lines,framerule=1pt,numbers=left,fontsize=\scriptsize}
+
+\tcbuselibrary{skins,breakable}
+
+\definecolor{shadecolor}{rgb}{0.9,0.9,0.9}
+\definecolor{lightgreen}{rgb}{0.8,0.95,0.8}
+
+\begin{document}
+
+\title{Testing the Pygmen\TeX{} package}
+\author{José Romildo Malaquias}
+\maketitle
+
+\section{The Pygmen\TeX{} package}
+
+This document demonstrates how to use the Pygment\TeX{} package to
+typeset code listings with \LaTeX{} and
+Pygments\footnote{\url{http://pygments.org/}}.
+
+Pygments is a generic syntax highlighter for general use in all kinds of
+software such as forum systems, wikis or other applications that need to
+prettify source code.
+
+Pygmen\TeX{} provides an environment and two commands for typesetting code
+listings in a \LaTeX{} document:
+\begin{itemize}
+  \item the \verb|pygmented| environment typesets its contents as a
+  source code listing,
+  \item the \verb|includepygmented| command typesets the contents of a
+  file, including the result in the \LaTeX{} document, and
+  \item the \verb|\pyginline| command typesets its contents, keeping the
+  result in the same line.
+\end{itemize}
+They accept many options that allow the user to configure the listing in
+many ways.
+
+Read the remaining of this document to have an idea of what the package
+is capable of.
+
+\section{How to use the package}
+
+In order to use the package, start by putting
+\begin{verbatim}
+\usepackage{pygmentex}
+\end{verbatim}
+in the preamble of the document.
+
+Use the environment or commands mentioned previously to include source
+code listings on your document.
+
+When compiling the document (with \texttt{pdflatex}, for instance), all
+the source code listings in the document wil be collected and saved in a
+temporary file with the extension \texttt{.snippets} in its name. Then
+the auxiliary program \texttt{pygmentex} (a Python application
+distributed with the Pygmen\TeX{} package) should be run taking this
+file as input. It will produce another temporary file with the extension
+\texttt{.pygmented}, containing \LaTeX{} code for the code listings
+previously collected. The next time the document is compiled, they are
+included to produce the final typeset document.
+
+The programming language of the listing code can be specified using the
+\verb|lang| option.
+
+To get a list of all available languages, execute the following command
+on the command line:
+\begin{verbatim}
+$ pygmentize -L lexers
+\end{verbatim}
+
+\section{First examples}
+
+A simple verbatim text is the first example.
+
+\begin{Example}
+\begin{pygmented}[]
+Hello world!
+  This is a simple demonstration text.
+\end{pygmented}
+\end{Example}
+
+The followig C program reads two integers and calculates their sum.
+
+\begin{Example}
+\begin{pygmented}[lang=c]
+#include <stdio.h>
+int main(void)
+{
+   int a, b, c;
+   printf("Enter two numbers to add: ");
+   scanf("%d%d", &a, &b);
+   c = a + b;
+   printf("Sum of entered numbers = %d\n", c);
+   return 0;
+}
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+  In this program, \pyginline[lang=c]|int| is a type and
+  \pyginline[lang=c]|"Enter two numbers to add: "| is a literal string.
+\end{Example}
+
+Next you can see a Java program to calculate the factorial of a number.
+
+\begin{Example}
+\inputpygmented[lang=java]{Factorial.java}
+\end{Example}
+
+\section{Choosing different Pygments styles}
+
+Instead of using the default style you may choose another stylesheet
+provided by Pygments by its name using the \verb|sty| option.
+
+To get a list of all available stylesheets, execute the following
+command on the command line:
+\begin{verbatim}
+$ pygmentize -L styles
+\end{verbatim}
+
+Creating your own styles is also very easy. Just follow the instructions
+provided on the website.
+
+As examples you can see a C program typeset with different styles.
+
+\begin{Example}
+\noindent
+\begin{minipage}[t]{0.49\linewidth}
+  \begin{pygmented}[lang=c,gobble=4,sty=murphy]
+    #include<stdio.h> 
+    main()
+    { int n;
+      printf("Enter a number: ");
+      scanf("%d",&n);
+      if ( n%2 == 0 )
+         printf("Even\n");
+      else
+         printf("Odd\n");
+      return 0;
+    }
+  \end{pygmented}
+\end{minipage}
+\hfil
+\begin{minipage}[t]{0.49\linewidth}
+  \begin{pygmented}[lang=c,gobble=4,sty=trac]
+    #include<stdio.h> 
+    main()
+    { int n;
+      printf("Enter a number: ");
+      scanf("%d",&n);
+      if ( n%2 == 0 )
+         printf("Even\n");
+      else
+         printf("Odd\n");
+      return 0;
+    }
+  \end{pygmented}
+\end{minipage}
+\end{Example}
+
+\section{Choosing a font}
+
+The value of the option \verb|font| is typeset before the content of the
+listing. Usualy it is used to specify a font to be used. See the
+following example.
+
+\begin{Example}
+\begin{pygmented}[lang=scala,font=\rmfamily\scshape\large]
+object bigint extends Application {
+  def factorial(n: BigInt): BigInt =
+    if (n == 0) 1 else n * factorial(n-1)
+
+  val f50 = factorial(50); val f49 = factorial(49)
+  println("50! = " + f50)
+  println("49! = " + f49)
+  println("50!/49! = " + (f50 / f49))
+}
+\end{pygmented}
+\end{Example}
+
+\section{Changing the background color}
+
+The option \verb|colback| can be used to choose a background color, as
+is shown in the folowing example.
+
+\begin{Example}
+\begin{pygmented}[lang=fsharp,colback=green!25]
+let rec factorial n = 
+    if n = 0 
+    then 1 
+    else n * factorial (n - 1)
+System.Console.WriteLine(factorial anInt)
+\end{pygmented}
+\end{Example}
+
+
+\section{Supressing initial characters}
+
+The option \verb|gobble| specifies the number of characters to suppress
+at the beginning of each line (up to a maximum of 9). This is mainly
+useful when environments are indented (Default: empty — no character
+suppressed).
+
+\begin{Example}
+A code snippet inside a minipage:
+\begin{minipage}[t]{.5\linewidth}
+    \begin{pygmented}[lang=d,gobble=8]
+        ulong fact(ulong n)
+        {
+          if(n < 2)
+            return 1;
+          else
+            return n * fact(n - 1);
+        }
+      \end{pygmented}
+\end{minipage}
+\end{Example}
+
+
+\section{Size of tabulator}
+
+The option \verb|tabsize| specifies the number of of spaces given by a
+tab character (Default: 8).
+
+\begin{Verbatim}[showtabs,tabsize=1]
+\begin{pygmented}[lang=common-lisp,tabsize=4]
+;; Triple the value of a number
+(defun triple	(X)
+	"Compute three times X."
+	(* 3 X))
+\end{pygmented}
+\end{Verbatim}
+
+\begin{pygmented}[lang=common-lisp,tabsize=4]
+;; Triple the value of a number
+(defun triple	(X)
+	"Compute three times X."
+	(* 3 X))
+\end{pygmented}
+
+
+\section{Numbering lines}
+
+The lines of a listing can be numbered. The followig options control
+numbering of lines.
+\begin{itemize}
+  \item Line numbering is enabled or disable with the \verb|linenos|
+  boolean option.
+  \item The number used for the first line can be set with the option
+  \verb|linenostart|.
+  \item The step between numbered lines can be set with the option
+  \verb|linenostep|.
+  \item The space between the line number and the line of the listing
+  can be set with the option \verb|linenosep|.
+\end{itemize}
+
+In the followig listing you can see a Scheme function to calculate the
+factorial of a number.
+
+\begin{Example}
+\begin{pygmented}[lang=scheme,linenos,linenostart=1001,linenostep=2,linenosep=5mm]
+;; Building a list of squares from 0 to 9.
+;; Note: loop is simply an arbitrary symbol used as
+;; a label. Any symbol will do.
+ 
+(define (list-of-squares n)
+  (let loop ((i n) (res '()))
+    (if (< i 0)
+        res
+        (loop (- i 1) (cons (* i i) res)))))
+\end{pygmented}
+\end{Example}
+
+\section{Captioning}
+
+The option \verb|caption| can be used to set a caption for the listing.
+The option \verb|label| allows the assignment of a label to the listing.
+
+Here is an example:
+
+\begin{Example}
+\begin{pygmented}[lang=c++,label=lst:test,caption=A \textbf{C++} example]
+// This program adds two numbers and prints their sum.
+#include <iostream>
+int main()
+{
+  int a;
+  int b;
+  int sum;
+  sum = a + b;
+  std::cout << "The sum of " << a << " and " << b
+            << " is " << sum << "\n";
+  return 0;
+}
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+  Listing \ref{lst:test} is a C++ program.
+\end{Example}
+
+\section{Escaping to \LaTeX{} inside a code snippet}
+
+The option \verb|texcomments|, if set to \texttt{true}, enables \LaTeX{}
+comment lines. That is, LaTex markup in comment tokens is not escaped
+so that \LaTeX{} can render it.
+
+The \verb|mathescape|, if set to \texttt{true}, enables \LaTeX{} math
+mode escape in comments. That is, \verb|$...$| inside a comment will
+trigger math mode.
+
+The option \verb|escapeinside|, if set to a string of length two,
+enables escaping to \LaTeX{}. Text delimited by these two characters
+is read as \LaTeX{} code and typeset accordingly. It has no effect in
+string literals. It has no effect in comments if \verb|texcomments| or
+\verb|mathescape| is set.
+
+Some examples follows.
+
+\begin{Example}
+\begin{pygmented}[lang=c++,texcomments]
+#include <iostream>
+using namespace std;
+main()
+{
+   cout << "Hello World";  // prints \underline{Hello World}
+   return 0;
+}
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\begin{pygmented}[lang=python,mathescape]
+# Returns $\sum_{i=1}^{n}i$
+def sum_from_one_to(n):
+    r = range(1, n + 1)
+    return sum(r)
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\begin{pygmented}[lang=c,escapeinside=||]
+
+if (|\textit{condition}|)
+    |\textit{command$_1$}|
+else
+    |\textit{command$_2$}|
+\end{pygmented}
+\end{Example}
+
+
+\section{Enclosing command and environment}
+
+After being prettified by Pygments, the listings are enclosed in a
+command (for \verb|\pyginline|) or in an environment (for
+\verb|pygmented| and \verb|includepygmented|). By default
+\verb|\pyginline| uses the command \verb|\efbox| from the \texttt{efbox}
+package, and \verb|pygmented| and \verb|includepygmented| use the
+environment \verb|mdframed| from the \texttt{mdframed} package.
+
+The enclosing command or environment should be configurable using a list
+of key-value pairs written between square brackets.
+
+The enclosing command for
+\verb|\pyginline| can be changed with the option
+\verb|inline method|. For instance, in the following the command
+\verb|\tcbox| from the \verb|tcolorbox| package is used:
+
+\begin{Example}
+  In the previous Java program,
+  \pyginline[lang=java,inline method=tcbox]|"Factorial of "| is a
+  literal string.
+\end{Example}
+
+The enclosing environment for \verb|pygmented| and
+\verb|includepygmented| can be changed with the option
+\verb|boxing method|. For instance, here is a hello world program in
+C\#, enclosed in a \verb|tcolorbox| environment:
+
+\begin{Example}
+\begin{pygmented}[lang=csharp,boxing method=tcolorbox]
+using System;
+class Program
+{
+    public static void Main(string[] args)
+    {
+        Console.WriteLine("Hello, world!");
+    }
+}
+\end{pygmented}
+\end{Example}
+
+Any option unknown to Pygmen\TeX{} are passed to the enclosing command
+or environment.
+
+For instance:
+
+\begin{Example}
+\begin{pygmented}[lang=xml,boxing method=tcolorbox,colframe=red,boxrule=2mm]
+<!-- This is a note -->
+<note>
+   <to>Tove</to>
+   <from>Jani</from>
+   <heading>Reminder</heading>
+   <body>Don't forget me this weekend!</body>
+</note>
+\end{pygmented}
+\end{Example}
+
+\section{Setting global options for Pygmen\TeX{}}
+
+Global options can be setting using the \verb|setpygmented| command.
+See the examples that follows.
+
+\begin{Example}
+\setpygmented{lang=haskell, colback=red!30, font=\ttfamily\small}
+
+\begin{pygmented}[]
+sum :: Num a => [a] -> a
+sum [] = 0
+sum (x:xs) = x + sum xs
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\begin{pygmented}[colback=blue!20, boxing method=tcolorbox]
+elem :: Eq a => a -> [a] -> Bool
+elem _ [] = False
+elem x (y:ys) = x == y || elem x ys
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\setpygmented{lang=snobol}
+
+\begin{pygmented}[]
+          OUTPUT = "What is your name?"
+          Username = INPUT
+          OUTPUT = "Thank you, " Username
+END
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\setpygmented{test/.style={colback=yellow!33,boxing method=tcolorbox,colframe=blue}}
+
+\begin{pygmented}[test, lang=vbnet]
+Module Module1
+    Sub Main() 
+        Console.WriteLine("Hello, world!")
+    End Sub
+End Module
+\end{pygmented}
+\end{Example}
+
+\begin{Example}
+\begin{pygmented}[lang=tcl]
+puts "Hello, world!"
+\end{pygmented}
+\end{Example}
+
+\section{More examples of inline code snippets}
+
+\begin{Example}
+  An inline source code snippet:
+  \pyginline[lang=c]|const double alfa = 3.14159;|.
+  This is a C declaration with initialization.
+\end{Example}
+
+\begin{Example}
+  \pyginline[lang=prolog,colback=yellow]=avo(A,B) :- pai(A,X), pai(X,B).=
+  is a Prolog clause. Its head is
+  \pyginline[lang=prolog,sty=emacs,colback=yellow,linecolor=red]=avo(A,B)=
+  and its body is
+  \pyginline[lang=prolog,sty=vim,colback=black,hidealllines]=pai(A,X), pai(X,B)=.
+\end{Example}
+
+\begin{Example}
+  See the identifier \pyginline[inline method=efbox,colback=green!25]|variable|,
+  which names something. String literals in C looks like
+  \pyginline[lang=c,inline method=tcbox,colback=blue!20,boxrule=2pt]|"hello, world!\n"|.
+\end{Example}
+
+\setpygmented{colback=shadecolor}
+
+\begin{Example}
+  This one
+  \pyginline[lang=ocaml,font=\ttfamily\scriptsize,topline=false]:let x = [1;2;3] in length x:
+  is an OCaml expression with local bindings. With OCaml one can do
+  imperative, functional and object oriented programming.
+\end{Example}
+
+\begin{Example}
+  Now some Java code:
+  \pyginline[lang=java,sty=colorful,font=\ttfamily\itshape,linewidth=1pt]|public int f(double x)|.
+  This is a method header.
+\end{Example}
+
+\section{More examples of displayed code snippets}
+
+\setpygmented{lang=scheme,colback=shadecolor,sty=emacs}
+
+In listing \ref{lst:fact} you can see a function definition in the
+Scheme language. This function computes the factorial of a natural
+number.
+\newline\rule{\linewidth}{2pt}
+\begin{pygmented}[
+  sty=emacs,
+  linenos,
+  label=lst:fact,
+  caption=A Scheme function.
+  ]
+(define fact
+    (lambda (n)
+        (if (= n 0)
+            1
+            (* n (fact (- n 1))))))
+\end{pygmented}
+
+Here you have some more code to further testing the package. Listing
+\ref{lst:haskell} is a Haskell program. When run this program interacts
+with the user asking the user name, reading a line input by the user,
+and showing a greeting message to the user.
+
+\inputpygmented[%
+  lang=haskell,
+  linenos,
+  linenostart=79831,
+  innerlinecolor=yellow, innerlinewidth=6pt,
+  middlelinecolor=blue, middlelinewidth=10pt,
+  outerlinecolor=green, outerlinewidth=12pt,
+  roundcorner=4,
+  colback=shadecolor,
+  caption=A haskell interactive program,
+  label=lst:haskell,
+  ]{pygmentex_demo.hs}
+
+This is a rule:
+
+\noindent\rule{\linewidth}{2pt}
+
+Now a Pascal procedure:
+
+\inputpygmented[
+  lang=delphi,
+  linewidth=1.5pt,
+  font=\ttfamily\sffamily\large,
+  colback=yellow
+  ]{pygmentex_demo.delphi}
+and a Pascal program
+\inputpygmented[lang=pascal,linenos,linenostart=5801]{pygmentex_demo.pas}
+
+A Python code snippet:
+
+\inputpygmented[
+  lang=python,
+  sty=emacs,
+  linenos,
+  linenostep=3,
+  linewidth=1pt,
+  colback=lightgreen
+  ]{pygmentex_demo.py}
+
+\section{Using code snippets in environments}
+
+The following is a \textbf{description} environment.
+
+\begin{description}
+  \item[An item] \lipsum[31]
+  \begin{pygmented}[lang=scala,colback=yellow,
+    % title=Item A
+    ]
+def qsort(xs: List[Int]): List[Int] =
+  xs match {
+    case Nil =>
+      Nil
+    case pivot :: tail =>
+      qsort(tail filter { _ < pivot }) :::
+        pivot :: qsort(tail filter { _ >= pivot })
+  }
+  \end{pygmented}
+  \lipsum[32]
+  
+  \item[Another item] \lipsum[33]
+  \begin{pygmented}[lang=lua,colback=yellow]
+function entry0 (o)
+  N=N + 1
+  local title = o.title or '(no title)'
+  fwrite('<LI><A HREF="#%d">%s</A>\n', N, title)
+end
+  \end{pygmented}
+  \lipsum[34]
+\end{description}
+
+\section{A long program}
+
+Here you can read the source code for a hand written lexical analyser
+for the \emph{straight-line} programming language that I have developed
+in Java.
+
+\inputpygmented[boxing method=mdframed,lang=java,sty=autumn,colback=red!8,font=\ttfamily\small,tabsize=2,frametitle=\emph{Ad hoc} lexical analyser]{pygmentex_demo.java}
+
+\section{Some fancy examples using \texttt{tcolorbox}}
+
+The followig example uses \texttt{tcolorbox} to typeset the code
+listing.
+
+\newcounter{example}
+\newlength{\examlen}
+\colorlet{colexam}{red!75!black}
+
+\begin{pygmented}[boxing method=tcolorbox,lang=scala,
+  title=Example \arabic{example}: hello from \texttt{Scala},
+  code={\refstepcounter{example}%
+        \settowidth{\examlen}{\Large\bfseries Example \arabic{example}}},%
+  coltitle=colexam,fonttitle=\Large\bfseries,
+  enhanced,breakable,
+  before=\par\medskip,
+  parbox=false,
+  frame hidden,interior hidden,segmentation hidden,
+  boxsep=0pt,left=0pt,right=3mm,toptitle=2mm,pad at break=0mm,
+  overlay unbroken={\draw[colexam,line width=1pt] (frame.north west)
+    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east)
+    --(frame.south west);
+    \draw[colexam,line width=2pt] ([yshift=0.5pt]frame.north west)
+    -- +(\examlen,0pt);},
+  overlay first={\draw[colexam,line width=1pt] (frame.north west)
+    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east);
+    \draw[red!75!black,line width=2pt] ([yshift=0.5pt]frame.north west)
+    -- +(\examlen,0pt);},
+  overlay middle={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
+    --([xshift=-0.5pt]frame.south east); },
+  overlay last={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
+    --([xshift=-0.5pt]frame.south east)--(frame.south west);}%
+  ]
+object HelloWorld extends App {
+  println("Hello, world!")
+}\end{pygmented}
+
+\begin{pygmented}[boxing method=tcolorbox,lang=java,
+  enhanced,colback=blue!10!white,colframe=orange,top=4mm,
+  enlarge top by=\baselineskip/2+1mm,
+  enlarge top at break by=0mm,pad at break=2mm,
+  fontupper=\normalsize,
+  overlay unbroken and first={%
+    \node[rectangle,rounded corners,draw=black,fill=blue!20!white,
+    inner sep=1mm,anchor=west,font=\small]
+    at ([xshift=4.5mm]frame.north west) {\strut\textbf{My fancy title}};},
+  ]
+public class Hello {
+  public static void main(String[] args) {
+    System.out.println("Hello, world!")
+  }
+}
+\end{pygmented}
+
+\begin{pygmented}[boxing method=tcolorbox,lang=haskell,
+  enhanced,sharp corners=uphill,
+  colback=blue!25!white,colframe=blue!25!black,coltext=blue!90!black,
+  fontupper=\Large\bfseries,arc=6mm,boxrule=2mm,boxsep=5mm,
+  borderline={0.3mm}{0.3mm}{white}
+  ]
+module Main (main) where
+
+main :: IO ()
+main = putStrLn "Hello, world!"
+\end{pygmented}
+
+\begin{pygmented}[boxing method=tcolorbox,lang=c++,
+  enhanced,frame style image=blueshade.png,
+  opacityback=0.75,opacitybacktitle=0.25,
+  colback=blue!5!white,colframe=blue!75!black,
+  title=My title
+  ]
+#include <iostream>
+using namespace std;
+int main(int argc, char** argv) {
+  cout << "Hello, world!" << endl;
+  return 0;
+}
+\end{pygmented}
+
+\begin{pygmented}[boxing method=tcolorbox,lang=d,
+  enhanced,attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},
+  colback=blue!5!white,colframe=blue!75!black,colbacktitle=red!80!black,
+  title=My title,fonttitle=\bfseries,
+  boxed title style={size=small,colframe=red!50!black}
+  ]
+/* This program prints a
+   hello world message
+   to the console.  */
+ 
+import std.stdio;
+ 
+void main()
+{
+    writeln("Hello, World!");
+}
+\end{pygmented}
+
+
+\section{Some fancy examples using \texttt{mdframed}}
+
+The followig example uses \texttt{mdframed} to typeset the code listing.
+
+\global\mdfdefinestyle{exampledefault}{%
+  linecolor=red,linewidth=3pt,%
+  leftmargin=1cm,rightmargin=1cm
+}
+
+\begin{pygmented}[boxing method=mdframed,lang=ada,style=exampledefault]
+with Ada.Text_IO;
+ 
+procedure Hello_World is
+ use Ada.Text_IO;
+begin
+    Put_Line("Hello, world!");
+end;
+\end{pygmented}
+
+\global\mdfapptodefinestyle{exampledefault}{%
+  topline=false,bottomline=false,
+}
+
+\begin{pygmented}[boxing method=mdframed,lang=pascal,style=exampledefault,frametitle={Saying \emph{hello} from Pascal}]
+program HelloWorld;
+ 
+begin
+  WriteLn('Hello, world!');
+end.
+\end{pygmented}
+
+\global\mdfdefinestyle{separateheader}{%
+  frametitle={%
+    \tikz[baseline=(current bounding box.east),outer sep=0pt]
+    \node[anchor=east,rectangle,fill=blue!20]
+    {\strut Saying \emph{hello} in Modula-2};},
+  innertopmargin=10pt,linecolor=blue!20,%
+  linewidth=2pt,topline=true,
+  frametitleaboveskip=\dimexpr-\ht\strutbox\relax,
+  frametitlerule=false,
+  backgroundcolor=white,
+}
+
+\begin{pygmented}[boxing method=mdframed,lang=modula2,style=separateheader]
+MODULE Hello;
+FROM STextIO IMPORT WriteString;
+BEGIN
+  WriteString("Hello World!");
+END Hello.
+\end{pygmented}
+
+
+\tikzset{titregris/.style =
+     {draw=gray, thick, fill=white, shading = exersicetitle, %
+      text=gray, rectangle, rounded corners, right,minimum height=.7cm}}
+\pgfdeclarehorizontalshading{exersicebackground}{100bp}
+          {color(0bp)=(green!40); color(100bp)=(black!5)}
+\pgfdeclarehorizontalshading{exersicetitle}{100bp}
+          {color(0bp)=(red!40);color(100bp)=(black!5)}
+\newcounter{exercise}
+\renewcommand*\theexercise{Exercise~n\arabic{exercise}}
+\makeatletter
+\def\mdf@@exercisepoints{}%new mdframed key:
+\define at key{mdf}{exercisepoints}{%
+    \def\mdf@@exercisepoints{#1}
+}
+\mdfdefinestyle{exercisestyle}{%
+  outerlinewidth=1em,outerlinecolor=white,%
+  leftmargin=-1em,rightmargin=-1em,%
+  middlelinewidth=1.2pt,roundcorner=5pt,linecolor=gray,
+  apptotikzsetting={\tikzset{mdfbackground/.append style ={%
+                       shading = exersicebackground}}},
+  innertopmargin=1.2\baselineskip,
+  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
+  skipbelow={-1em},
+  needspace=3\baselineskip,
+  frametitlefont=\sffamily\bfseries,
+  settings={\global\stepcounter{exercise}},
+  singleextra={%
+      \node[titregris,xshift=1cm] at (P-|O) %
+         {~\mdf at frametitlefont{\theexercise}\hbox{~}};
+      \ifdefempty{\mdf@@exercisepoints}%
+      {}%
+      {\node[titregris,left,xshift=-1cm] at (P)%
+        {~\mdf at frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
+   },
+  firstextra={%
+      \node[titregris,xshift=1cm] at (P-|O) %
+         {~\mdf at frametitlefont{\theexercise}\hbox{~}};
+      \ifdefempty{\mdf@@exercisepoints}%
+      {}%
+      {\node[titregris,left,xshift=-1cm] at (P)%
+        {~\mdf at frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
+   },
+}
+\makeatother
+
+\begin{pygmented}[boxing method=mdframed,lang=go,style=exercisestyle]
+// hello world in 'go'
+package main
+ 
+import "fmt"
+ 
+func main() {
+   fmt.Println("Hello, world!")
+}
+\end{pygmented}
+
+\begin{pygmented}[boxing method=mdframed,lang=objective-c,style=exercisestyle,exercisepoints=10]
+/* hello from objective-c */
+
+#import <stdio.h>
+#import <Foundation/Foundation.h>
+ 
+int main(void)
+{
+    NSLog(@"Hello, world!\n");
+    return 0;
+}
+\end{pygmented}
+
+\mdfdefinestyle{another}{%
+  linecolor=red,middlelinewidth=2pt,%
+  frametitlerule=true,%
+  apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
+        shade,left color=white, right color=blue!20}}},
+  frametitlerulecolor=green!60,
+  frametitlerulewidth=1pt,
+  innertopmargin=\topskip,
+}
+
+\begin{pygmented}[boxing method=mdframed,lang=c,style=another,frametitle={Hello from C}]
+#include <stdio.h>
+int main(int argc, char **argv) {
+  printf("Hello, world!\n");
+  return 0;
+}
+\end{pygmented}
+
+
+\section{Conclusion}
+
+That is all.
+
+\end{document}


Property changes on: trunk/Master/texmf-dist/doc/latex/pygmentex/pygmentex_demo.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/scripts/pygmentex/pygmentex.py
===================================================================
--- trunk/Master/texmf-dist/scripts/pygmentex/pygmentex.py	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/scripts/pygmentex/pygmentex.py	2020-12-21 22:09:04 UTC (rev 57190)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2
+#! /usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """
@@ -8,11 +8,11 @@
     PygmenTeX is a converter that do syntax highlighting of snippets of
     source code extracted from a LaTeX file.
 
-    :copyright: Copyright 2014 by José Romildo Malaquias
+    :copyright: Copyright 2020 by José Romildo Malaquias
     :license: BSD, see LICENSE for details
 """
 
-__version__ = '0.8'
+__version__ = '0.10'
 __docformat__ = 'restructuredtext'
 
 import sys
@@ -27,6 +27,7 @@
 from pygments.util import get_bool_opt, get_int_opt
 from pygments.lexer import Lexer
 from pygments.token import Token
+from pygments.util import guess_decode
 
 ###################################################
 # The following code is in >=pygments-2.0
@@ -56,17 +57,17 @@
             realoutfile = outfile
             outfile = StringIO()
 
-        outfile.write(u'\\begin{Verbatim}[commandchars=\\\\\\{\\}')
+        outfile.write(r'\begin{Verbatim}[commandchars=\\\{\}')
         if self.linenos:
             start, step = self.linenostart, self.linenostep
-            outfile.write(u',numbers=left' +
-                          (start and u',firstnumber=%d' % start or u'') +
-                          (step and u',stepnumber=%d' % step or u''))
+            outfile.write(',numbers=left' +
+                          (start and ',firstnumber=%d' % start or '') +
+                          (step and ',stepnumber=%d' % step or ''))
         if self.mathescape or self.texcomments or self.escapeinside:
-            outfile.write(u',codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}')
+            outfile.write(r',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
         if self.verboptions:
-            outfile.write(u',' + self.verboptions)
-        outfile.write(u']\n')
+            outfile.write(',' + self.verboptions)
+        outfile.write(']\n')
 
         for ttype, value in tokensource:
             if ttype in Token.Comment:
@@ -73,7 +74,7 @@
                 if self.texcomments:
                     # Try to guess comment starting lexeme and escape it ...
                     start = value[0:1]
-                    for i in xrange(1, len(value)):
+                    for i in range(1, len(value)):
                         if start[0] != value[i]:
                             break
                         start += value[i]
@@ -129,7 +130,7 @@
             else:
                 outfile.write(value)
 
-        outfile.write(u'\\end{Verbatim}\n')
+        outfile.write('\\end{Verbatim}\n')
 
         if self.full:
             realoutfile.write(DOC_TEMPLATE %
@@ -232,7 +233,7 @@
 '''
 
 
-def pyg(outfile, n, opts, extra_opts, text, usedstyles, inline_delim = ''):
+def pyg(outfile, outencoding, n, opts, extra_opts, text, usedstyles, inline_delim = ''):
     try:
         lexer = get_lexer_by_name(opts['lang'])
     except ClassNotFound as err:
@@ -260,27 +261,8 @@
     if tabsize:
         lexer.tabsize = tabsize
 
-    encoding = opts['encoding']
-    if encoding == 'guess':
-        try:
-            import chardet
-        except ImportError:
-            try:
-                text = text.decode('utf-8')
-                if text.startswith(u'\ufeff'):
-                    text = text[len(u'\ufeff'):]
-                    encoding = 'utf-8'
-            except UnicodeDecodeError:
-                text = text.decode('latin1')
-                encoding = 'latin1'
-        else:
-            encoding = chardet.detect(text)['encoding']
-            text = text.decode(encoding)
-    else:
-        text = text.decode(encoding)
-
     lexer.encoding = ''
-    _fmter.encoding = encoding
+    # _fmter.encoding = outencoding
 
     stylename = opts['sty']
 
@@ -367,7 +349,7 @@
     r'^<@@pygmented at input@(\d+)\n(.*)\n([\s\S]*?)\n>@@pygmented at input@\1$',
     re.MULTILINE)
 
-def convert(code, outfile):
+def convert(code, outfile, outencoding):
     """
     Convert ``code``
     """
@@ -393,6 +375,7 @@
         m = _re_inline.match(code, pos)
         if m:
             pyg(outfile,
+                outencoding,
                 m.group(1),
                 parse_opts(opts.copy(), m.group(2)),
                 '',
@@ -405,6 +388,7 @@
         m = _re_display.match(code, pos)
         if m:
             pyg(outfile,
+                outencoding,
                 m.group(1),
                 parse_opts(opts.copy(), m.group(2)),
                 '',
@@ -415,15 +399,16 @@
 
         m = _re_input.match(code, pos)
         if m:
+            opts_new = parse_opts(opts, m.group(2))
             try:
-                filecontents = open(m.group(3), 'rb').read()
+                filecontents, inencoding = read_input(m.group(3), opts_new['encoding'])
             except Exception as err:
-                sys.stderr.write('Error: cannot read input file: ')
-                sys.stderr.write(str(err))
+                print('Error: cannot read input file: ', err, file=sys.stderr)
             else:
                 pyg(outfile,
+                    outencoding,
                     m.group(1),
-                    parse_opts(opts, m.group(2)),
+                    opts_new,
                     "",
                     filecontents,
                     usedstyles)
@@ -435,8 +420,18 @@
 
     outfile.write(GENERIC_DEFINITIONS_2)
 
+def read_input(filename, encoding):
+    with open(filename, 'rb') as infp:
+        code = infp.read()
 
+    if not encoding or encoding == 'guess':
+        code, encoding = guess_decode(code)
+    else:
+        code = code.decode(encoding)
 
+    return code, encoding
+
+
 USAGE = """\
 Usage: %s [-o <output file name>] <input file name>
        %s -h | -V
@@ -486,7 +481,7 @@
         return 0
 
     if opts.pop('-V', None) is not None:
-        print('PygmenTeX version %s, (c) 2010 by José Romildo.' % __version__)
+        print('PygmenTeX version %s, (c) 2020 by José Romildo.' % __version__)
         return 0
  
     if len(args) != 1:
@@ -494,10 +489,9 @@
         return 2
     infn = args[0]
     try:
-        code = open(infn, 'rb').read()
+        code, inencoding = read_input(infn, "guess")
     except Exception as err:
-        sys.stderr.write('Error: cannot read input file: ')
-        sys.stderr.write(str(err))
+        print('Error: cannot read input file: ', err, file=sys.stderr)
         return 1
 
     outfn = opts.pop('-o', None)
@@ -507,11 +501,10 @@
     try:
         outfile = open(outfn, 'w')
     except Exception as err:
-        sys.stderr.write('Error: cannot open output file: ')
-        sys.stderr.write(str(err))
+        print('Error: cannot open output file: ', err, file=sys.stderr)
         return 1
 
-    convert(code, outfile)
+    convert(code, outfile, inencoding)
 
     return 0
 

Modified: trunk/Master/texmf-dist/tex/latex/pygmentex/pygmentex.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/pygmentex/pygmentex.sty	2020-12-21 22:02:51 UTC (rev 57189)
+++ trunk/Master/texmf-dist/tex/latex/pygmentex/pygmentex.sty	2020-12-21 22:09:04 UTC (rev 57190)
@@ -2,7 +2,7 @@
 
 \NeedsTeXFormat{LaTeX2e}
 
-\ProvidesPackage{pygmentex}[2014/08/12 v0.8 A Pygmentex layer for LaTeX]
+\ProvidesPackage{pygmentex}[2020/12/21 v0.10 A Pygmentex layer for LaTeX]
 
 \RequirePackage{fancyvrb}
 \RequirePackage{color}
@@ -13,9 +13,9 @@
 \RequirePackage{efbox}
 \RequirePackage[framemethod=tikz]{mdframed}
 
-%\DeclareCaptionType[within=chapter]{code}[Listagem][Lista de listagens]
-\DeclareCaptionType{code}[Listagem][Lista de listagens]
-\captionsetup[code]{position=top}
+%\DeclareCaptionType[within=chapter]{pygcode}[Listagem][Lista de listagens]
+\DeclareCaptionType{pygcode}[Listagem][Lista de listagens]
+\captionsetup[pygcode]{position=top}
 
 % =========================================================
 % Auxiliary:
@@ -246,7 +246,7 @@
   %
   \ifdefined\pygmented at opt@label
     \def\pygmented at title{%
-      \captionof{code}{\label{\pygmented at opt@label}\pygmented at opt@caption}%
+      \captionof{pygcode}{\label{\pygmented at opt@label}\pygmented at opt@caption}%
       % \nopagebreak
       \vskip -0.7\baselineskip
     }%
@@ -253,7 +253,7 @@
   \else
     \ifdefined\pygmented at opt@caption
       \def\pygmented at title{%
-        \captionof{code}{\pygmented at opt@caption}%
+        \captionof{pygcode}{\pygmented at opt@caption}%
         % \nopagebreak
         \vskip -0.7\baselineskip
       }%



More information about the tex-live-commits mailing list.