Tag Info

Hot answers tagged

20

LaTeX macros for defining custom commands and environments include: \newcommand \newcommand* \renewcommand \renewcommand* \providecommand \providecommand* \newenvironment \newenvironment* \renewenvironment \renewenvironment* It is best to start with these since you should prefer them to TeX macros such as \def. However, sometimes only the TeX macros will ...


15

The problem is quite subtle. In general, a hyphen is allowed to be in an environment name, just like any other non special character (and also some special ones, actually). However, it's not possible to use some of them in a verbatim environment, because the verbatim mode makes them active; in latex.ltx you find ...


9

In his answer egreg has already explained that the hyphen - has a different catcode inside the verbatim environment. Package fancyvrb saves the environment name from \begin{my-environ} in \FV@EnvironName. - has the catcode before the catcode changes of the verbatim environment, usually 12 (other). Then inside the environment fancyvrb looks for \end{...} and ...


7

The arguments passed to an environment are not available in the code that is executed at the end. You can get around this by saving them using global declarations in the initialisation code. Also, there is nothing in your example to prevent the body of the environment (i.e. between \begin{solution} and \end{solution}) from being processed in the false case. ...


6

With the help of \NewEnviron from the environ package \documentclass{article} \usepackage{tikz} \usepackage{environ} \NewEnviron{smallenvironment}{% \tikzstyle{mybox} = [draw=red, rectangle,inner sep=5pt, inner ysep=5pt]% \begin{center}% \begin{tikzpicture}% \node [mybox] (box){% ...


6

First of all, the definition of rubrique, being a new environment, lacks the ending part... Then, it is defined with a tabular inside it, which is not allowed to break into pages. The solution may be to load the package longtable \usepackage{longtable} and to substitute tabular with longtable in the definition of rubrique: ...


5

Grab the contents of the conditional environment using environ: \documentclass{article} \usepackage{empheq,environ} \NewEnviron{pdfORht}[3][]{% \ifdefined\HCode %htlatex \begin{#3} \BODY \end{#3} \else% pdflatex \begin{#2}[#1]{#3} \BODY \end{#2} \fi% } \begin{document} \begin{pdfORht}[box=\fbox]{empheq}{align*} ...


5

Here's a solution using the xparse package, and its NewDocumentEnvironment which allows the use of arguments in the \end{environment} code. The important part is % solution environment \NewDocumentEnvironment{solution}{O{true}}{% \ifthenelse{\boolean{#1}}{\par{\sffamily\bfseries Solution}\par}{\setbox0=\hbox\bgroup} }{% ...


4

Place the proof inside the figure environment, or else the "fact" may end up in a different location than the figure. EDITED to allow for multi-figures and page breaks in proofs (by using the \captionof{figure}{} approach). \documentclass{article} \usepackage{caption} \usepackage{xcolor} \usepackage{framed} \usepackage{lipsum} ...


4

I'd suggest you to use a \list (as many of the standard LaTeX2e environments do): \documentclass{article} \usepackage{lipsum}% just to generate text for the example \newenvironment{myenv} {\list{}{\leftmargin=0pt}\item\relax}{\endlist} \begin{document} \lipsum[4] \begin{myenv} \lipsum[4] \end{myenv} \begin{myenv} \lipsum[4] \end{myenv} \lipsum[4] ...


4

\addvspace only inserts vertical space up to some maximum: \documentclass{article} \usepackage{lipsum} \newenvironment{myenv} {\par\addvspace{\baselineskip}}% \begin{myenv} {\par\addvspace{\baselineskip}}% \end{myenv} \begin{document} \lipsum[4] \begin{myenv} \lipsum[4] \end{myenv} \begin{myenv} \lipsum[4] \end{myenv} \lipsum[4] \end{document} ...


4

For fancyvrb, you need to use \VerbatimEnvironment before the \begin{Verbatim}. That tells fancyvrb to detect the name of the current environment, and look for the end of that environment, rather than looking for a literal \end{Verbatim}. You will probably want to use a proper framing package to provide the background color...that way you won't have to ...


4

You have some options. Since you are using listings as floats, you may use float=h as the option \begin{codice_c++}[float=h,,caption={c1}] Also since you are using placeins, you can use \usepackage[section]{placeins} thereby restricting the placement of (all) floats within the section. Code: \documentclass[a4paper,11pt]{article} ...


3

\refstepcounter should be used before \label. \refstepcounter defines \@currentlabel that is used by \label. \documentclass{book} \usepackage{lipsum} \usepackage{mathpazo} \newcounter{exam}[chapter] \setcounter{exam}{0} \renewcommand{\theexam}{\thechapter.\arabic{exam}} % % Method 1 % ...


3

Karl has already shown you about forming a newenvironment using environ. I will point out some improvements to your tikzpicture code. Use tikzset instead of tikzstyle. No need of specifying ysep when you have already inner sep. No need of using minipage inside the node. You can specify text width= 0.85\textwidth, minimum width = 0.85\textwidth in node ...


3

You have to set \@currentlabelname if you wish nameref to extract the appropriate content. Since you specify the question title using \questtitle, you could incorporate this addition using: \makeatletter \newcommand{\questtitle}[1]{% \renewcommand{\givenquesttitle}{#1}% \protected@edef\@currentlabelname{Quest~\givenquestid: #1}} \makeatother


3

\\ is used by the tabbing environment to break lines. Since you've issued it inside the environment foo, the environment is not ended before the linebreak and tabbing gets confused. That's the reason of the error forgotten \endgroup. If you let foo end before the linebreak, you don't get the error, as in following MWE: ...


3

An interface similar to \NewEnviron would be a welcome addition to xparse; but you can use it indirectly: \documentclass{article} \usepackage{xparse,environ} \NewDocumentEnvironment{env}{ O{default} } {\Environenv{#1}} {\endEnvironenv} \NewEnviron{Environenv}[1] {Do something with #1 and \BODY} \begin{document} \begin{env} What is this? Another ...


2

To reiterate from my comment, the problem with your MWE is the fact that your environment, as written, has one optional argument, and one mandatory argument. Your first use case fails to provide the mandatory argument (the label). Thus, the environment grabs the next thing, which is the first letter of your proof, and calls it the label. If your first use ...


2

I have a different proposal; instead of complicating your life, just redefine proof in such a way that \begin{proof}* doesn't print the proof. Instead of * you can choose whatever (single) character you prefer. After all, it's just a switch, so be it. \documentclass{scrartcl} \usepackage{xparse} \usepackage{environ} \usepackage{amsthm} %% save the ...


2

It seems easier to define the acknowledgments environment as an "abstract wrapper" using the following: \documentclass{article} \usepackage{filecontents,lipsum} \begin{filecontents*}{mystyle.sty} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{mystyle} \newenvironment{acknowledgments} {\renewcommand{\abstractname}{Acknowledgments}% Abstract > ...


2

(Note: there are parts of this solution that are sub-optimal, and I'm aware of that, but I'll have to fix that later. I'll remove this note when I find the time to improve things.) You can change the files theorems-ams.module and theorems-ams.inc, or better create copies as described in my answer to How to make "claim" environments look like ...


2

Try the environ package. \documentclass{article} \usepackage{environ} \NewEnviron{test} {\textsc{\MakeLowercase{\BODY}}} \begin{document} \begin{test} THIS IS A TEST \end{test} \end{document} Everything between \begin{test} and \end{test} is scooped up and stored in the macro \BODY.


2

To change the representation for the first level of an enumerate environment, you can redefine \theenumi; the default definition on your example is \renewcommand\theenumi{{\rm (\roman{enumi})} so the label numbering will use lower-case Roman numerals; to get Arabic numbering you need to change it to \renewcommand\theenumi{{\rmfamily(\arabic{enumi})}} ...


1

First, here is a solution that uses only the xcolor package and the standard verbatim environment. But it is not a new environment, per se, and so does not directly answer the OP's question (for that, see below). \documentclass{article} \usepackage{xcolor} \fboxrule=1pt \begin{document} \setbox0=\hbox{\begin{minipage}{3in} \color{red!90} \begin{verbatim} ...


1

We can find some workarounds. Solution A: We could generate a temporary file during the TeX run, close it a load it back to TeX per every command call, please see mal-dot2tex-file.tex. We can run all LaTeX engines. Solution B: We could use LuaTeX to generate that part of the TeX code for us and run it on-the-fly, please see mal-dot2tex.tex. We can run ...


1

Here is a MWE based on etoolbox: \documentclass{article} \usepackage{etoolbox} %\edef\printsolution{} % Uncomment to print solutions. \newcommand{\nosolution}[1]{% \ifdefmacro{\printsolution}{}{#1}% } \newcommand{\solution}[1]{% \ifdefmacro{\printsolution}{#1}{}% }{} \begin{document} \nosolution{ No solution. } \solution{ Solution. } ...


1

The exsheets package has ready made solutions for this. The following example \documentclass{article} \usepackage[demo]{graphicx} \usepackage{exsheets} % custom headings: \DeclareInstance{exsheets-heading}{myheading}{default}{ runin = true , title-post-code = \space , attach = { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) ...



Only top voted, non community-wiki answers of a minimum length are eligible