I try to rename environment codeexample used in tikz document, but fail to use the tricks as in Wrap an environment.
This is related to tkzexample: source and output side-by-side. The pgfmanual-en-macros.tex is used in \input{pgfmanual-en-macros.tex} (I do not know how to minimize it and upload as a attachment)
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{tkzexample}
\usepackage[a4paper,left=2.25cm,right=2.25cm,top=2.5cm,bottom=2.5cm,nohead]{geometry}%pgfmanual-en-main-preamble.tex
\input{pgfmanual-en-macros.tex}
\let\bcExample\codeexample
\let\ecExample\endcodeexample
\renewenvironment{codeexample} {\bcExample[]} {\ecExample}
\let\cExample\codeexample
\let\endcExample\endcodeexample
\newenvironment{eExample} {\bcExample[]} {\ecExample}
\begin{document}
When executed, that is, run via |pdflatex| or via |latex| followed by |dvips|,
the resulting will contain something that looks like this:
%
\begin{codeexample}
We are working on
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}.
\end{codeexample}
cExample
%\begin{cExample}
We are working on
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}.
%\end{cExample}
eExample
%\begin{eExample}
We are working on
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}.
%\end{eExample}
\end{document}
using renewenvironment{codeexample} works, but using \let\cExample\codeexample and \newenvironment{eExample} to rename/copy the new environment codeexample throw errors.
pgfmanual-en-macros.texwhich doesn't even appear to be the official one? With\usepackage[listings]{tcolorbox} \newtcblisting{codeexample}[1][]{#1}instead of the\input{pgfmanual-en-macros.tex}, I see no error either after uncommenting the\begin{...}and\end{...}markers forcExampleandeExample. – frougon Jul 25 '19 at 05:46cExampleandeExamplein the body. I am usingcodeexampleextract from pgfmanual, it has syntax highlights. The one by\newtcblisting{codeexample}does not have syntax highlights.pgfmanual-en-macros.texis beyond my scope, after delete 2 definitions, the\renewenvironment{codeexample}works as expected, I am not able to trim the redundant code. – Chen Deng-Ta Jul 25 '19 at 08:07\newtcblisting{codeexample}[1][]{#1}doesn't match your final requirements. What matters to me is to be able to reproduce your error with a minimal example. I've just tried this with XeLaTeX under TL 2019 (with\usepackage[listings]{tcolorbox} \newtcblisting{codeexample}[1][]{#1}instead of the\input{pgfmanual-en-macros.tex}), this doesn't produce an error and seems to work fine. I hope someone else can reproduce the problem (by the way, double notifications with @ don't work here, unfortunately). – frougon Jul 25 '19 at 08:14newtcblisting{...}way is answer in egreg's answer, where the tricks work. Here I am puzzled why thecodeexamplein pgfmanual throws error if using\codeexampleandendcodeexampleincExampleandeExample– Chen Deng-Ta Jul 25 '19 at 08:28