Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theorem/Lemma/Definition Custom Blocks #152

Closed
coatless opened this issue Jul 12, 2016 · 24 comments
Closed

Theorem/Lemma/Definition Custom Blocks #152

coatless opened this issue Jul 12, 2016 · 24 comments
Milestone

Comments

@coatless
Copy link

I'm trying to provide a way to use theorems/lemmas/definitions.

The main way I see about going about this is via the custom block declaration:

To enable this feature I'm running into a roadblock of not being able to:

  1. supply non-body content like a header (e.g. theorem name)
  2. autoincrement/number

For 1. it seems as if caption = "Fermat's Last Theorem" could be passed through to the block more options would be possible.

For 2., I'm pretty sure this isn't possible due to the restriction on the \ref tag.

@yihui
Copy link
Member

yihui commented Jul 12, 2016

I did think about this when I started this project, but I didn't come up with a simple solution. I'm preparing the CRAN release of bookdown right now, and I'll reconsider this feature in the next version. Basically there are two possible ways on my mind: 1) As you described, use custom blocks (the major drawback is that it is not easy to use all Markdown features in these blocks at the moment; #117); 2) Hack the definition list or example list http://pandoc.org/README.html#definition-lists using some sort of special tokens and restore them to thereoms/lemmas/whatever.

@yihui yihui modified the milestone: v0.2 Jul 12, 2016
@yihui yihui closed this as completed in 2f9c5f9 Oct 4, 2016
@yihui
Copy link
Member

yihui commented Oct 4, 2016

All these environments have been implemented. Please see the documentation at https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html

@coatless
Copy link
Author

coatless commented Oct 4, 2016

Praise be @yihui .

@endri81
Copy link

endri81 commented Oct 10, 2016

Environment theorem not working for me. When I compile pdf I get:

In get_engine(options$engine) :
  Unknown language engine 'theorem' (must be registered via knit_engines$set()).

and theorem show just the typed text with different font but not at all as in the documentation

@coatless
Copy link
Author

After a bit of configuration, the theorem environments do work.

Questions:

  1. Do you have the latest bookdown version? devtools::install_github("rstudio/bookdown")
  2. Are you building under bookdown::pdf_book?
  3. Did you define theorem environments?
    https://github.com/SMAC-Group/TTS/blob/cb0e8f4f46857b88d11bd429d7be4bc3f2944e7c/preamble.tex#L54-L78

@endri81
Copy link

endri81 commented Oct 10, 2016

Thank you @coatless very much.
I made the changes now everything works fine
Best Regards

@yihui
Copy link
Member

yihui commented Oct 10, 2016

2 and 3 are not necessary. Theorems work for HTML/EPUB output as well. You can also leave the preamble empty, and bookdown will define the environments for you. The documentation said:

For the sake of simplicity and consistency, we do not recommend you to do this (define environments in LaTeX).

@coatless
Copy link
Author

@yihui


I agree that 2 is unnecessary. This was primarily to make sure that the document was not being knitted (if open in a non-bookdown rstudio project). This is a known issue that a few of my collaborators have run into.


On 3, I disagree. I'm not sure that theorem has been defined for the pdf_book.

Without defining the theorem and other environments in the premable.tex, I received:

! LaTeX Error: Environment theorem undefined.

I came to this realization after observing the example text, which explicitly loads amsthm:

\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
\thm@preskip=8pt plus 2pt minus 4pt
\thm@postskip=\thm@preskip
}
\makeatother

@yihui
Copy link
Member

yihui commented Oct 10, 2016

@coatless I'm loading amsthm explicitly only because I wanted to increase the vertical space above the theorems in the bookdown book, which uses the LaTeX class from Chapman & Hall and the spacing above theorems was too tight. This is only for cosmetic purposes. If your book cannot compile without defining the theorem environments, it is either a bookdown bug or there was something wrong in your book, and I'll need a reproducible example. I didn't define the theorem environments in the bookdown book, and it generates the PDF without any problems.

@stevepowell99
Copy link

Is there any way to get a list of definitions / theorems etc at the end of the book?

@yihui
Copy link
Member

yihui commented Nov 21, 2016

@stevepowell99 Possible, but not very straightforward. Theorems are not different with normal R code chunks, so chunk references will still work: http://yihui.name/knitr/demo/reference/ Basically echo=FALSE to hide a theorem, and echo=TRUE with the same label to show it later. I'm curious why that could be possibly helpful to readers, though. Personally I very much hate figures/tables being placed at the end of a paper (per requirement of some old-fashioned journals), and I also feel it is inconvenient when theorems are not where they are actually used.

@stevepowell99
Copy link

sorry, I just meant to place an index of definitions at the end, but to leave the actual definitions where they belong, in the text.

@yihui
Copy link
Member

yihui commented Nov 21, 2016

@stevepowell99 If you mean a LaTeX index, please see the section Index in the docs: https://bookdown.org/yihui/bookdown/ If you mean something else, I think it will be better to explain it with an example.

@stevepowell99
Copy link

V sorry if I wasn't clear. The short version is this: presumably bookdown, by the end of the book, knows all the definition labels which have been created in the text? So one could just loop / lapply through them and print them all out, aka Index of Definitions. So the user can look to see, aha, where is "bar2" defined, here it is in the Index of Definitions, let's click on it to get to the definition of bar2 in the text.

Long version:
I just meant something like this, (in markdown, not latex)
in text:

A bar1 is defined as a foo.

...

A bar2 is similarly defined as a foobar.

and then, presumably at the end, I can already do this...

##Index of definitions
@ref(def:bar1)
@ref(def:bar2)

... but I have to know all the labels I created in the text and I have to type them. If bookdown knows about all the definition labels I have created, it could make such an index automatically.

@yihui
Copy link
Member

yihui commented Nov 22, 2016

@stevepowell99 By the end of the book, you can obtain all labels of definitions via knitr::all_labels(engine == 'definition'). You can certainly create cross-references automatically, but the problem is you only have the labels, so readers can only see definition numbers like X.Y, and there are no names/terms for the definitions. This issue is not impossible to solve. You may post a question on StackOverflow and I may answer it there, since I think other users may benefit from it, too.

@yihui
Copy link
Member

yihui commented Nov 24, 2016

@stevepowell99 FYI: finally found some time to type an answer on SO http://stackoverflow.com/q/40735727/559676

@stevepowell99
Copy link

Is there any way to change the names Lemma, Theorem etc which are actually printed at the start of each block, e.g. for another language?

@yihui
Copy link
Member

yihui commented Jan 4, 2017

@stevepowell99
Copy link

thanks - now I can't see how to translate the token (PART) - is this not possible?

@yihui
Copy link
Member

yihui commented Feb 10, 2017

@stevepowell99 No. For HTML output, you only get part numbers like I, II, III, IV, ... For LaTeX output, you have to figure it out by yourself how to change the PART name (may be something like \partname).

@endri81
Copy link

endri81 commented Feb 10, 2017

For LateX output you have to put the code below before the chapter which begins your part:

(PART) Name of part {-}

For example if you have book organized:

Part 1

Chapter 1

Chapter 2

...

Part 2

Chapter 1

Chapter 2

...

So you begin Chapter 1 in Part 1 with

(PART) Name of part 1 {-}

and Chapter 1 in Part 2 with

(PART) Name of part 2 {-}

Like this you get the organization you want

@stevepowell99
Copy link

Thanks @endri81 - I don't have chapter numbering so had left off the {-}, and that led to me seeing PART actually printed before the header, which I didn't want, which is why I wanted the translation ... In short: when writing (PART), leave the {-} in place, as instructed in the docs, even if you aren't using chapter numbering.

@fyuniv
Copy link

fyuniv commented Jan 17, 2020

@stevepowell99 https://bookdown.org/yihui/bookdown/internationalization.html

In latex
\begin{proof}[Sketch of proof] will be printed as

Sketch of proof.

In bookdown, it prints at

Proof.(Sketch of proof)

Is it possible the temporarily change the printed name of the proof environment?

@github-actions
Copy link

github-actions bot commented Nov 6, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants