LaTeX environment using list widget with counter

66 views
Skip to first unread message

Pak

unread,
Jun 6, 2021, 8:56:54 AM6/6/21
to TiddlyWiki
Hello,

I would like to imitate a latex environment using list widget and transclude the contents in the tiddlers.

Suppose I have 3 tiddlers: tid-thm-a, tid-thm-b, tid-thm-c I would like to transclude them in a tiddler so that it displays the following:

Theorem 1. (optional caption) (...contents in tid-thm-a... displayed in block mode, but the first line should be on the same line as Theorem 1}

Theorem 2. (optional caption) (...contents in tid-thm-b... displayed in block mode, but the first line should be on the same line as Theorem 2}

Theorem 3. (optional caption) (...contents in tid-thm-c... displayed in block mode, but the first line should be on the same line as Theorem 3}

My initial attempt is

<$list filter="tid-thm-a tid-thm-b tid-thm-c">
Theorem x. (<$view field=caption/>) <$transclude mode="block"/>
</$list>

But there are two problems.
1. How do I make x run as a counter?
2. The contents of transcluded tiddlers appear on the next line, not after the word Theorem x.

If I use LaTeX, I would perhaps do something like:
\begin{theorem}
\input{tid-thm-a}
\end{theorem}

How do I make it behave similar to LaTeX? Any help is appreciated. 

Pak

Mohammad Rahmani

unread,
Jun 6, 2021, 10:56:01 AM6/6/21
to tiddl...@googlegroups.com
Hi Pak,

On Sun, Jun 6, 2021 at 5:26 PM Pak <pack...@gmail.com> wrote:
Hello,

I would like to imitate a latex environment using list widget and transclude the contents in the tiddlers.

Suppose I have 3 tiddlers: tid-thm-a, tid-thm-b, tid-thm-c I would like to transclude them in a tiddler so that it displays the following:

Theorem 1. (optional caption) (...contents in tid-thm-a... displayed in block mode, but the first line should be on the same line as Theorem 1}

Theorem 2. (optional caption) (...contents in tid-thm-b... displayed in block mode, but the first line should be on the same line as Theorem 2}

Theorem 3. (optional caption) (...contents in tid-thm-c... displayed in block mode, but the first line should be on the same line as Theorem 3}

My initial attempt is

<$list filter="tid-thm-a tid-thm-b tid-thm-c">
Theorem x. (<$view field=caption/>) <$transclude mode="block"/>
</$list>

But there are two problems.
1. How do I make x run as a counter?
2. The contents of transcluded tiddlers appear on the next line, not after the word Theorem x.

I think  Theorem x. (<$view field=caption/>) should appear in the same line
but <$transclude mode="block"/>  starts in the next like note to mode=block which creates a div

I also use macros a lot!

example: (note how macro parameter is used inside KaTeX block!)

\define pellet(cmp:A)
$$
D_{e $cmp$} \frac{1}{r^2} \frac{\partial C_{$cmp$}}{\partial x} (r^2 \frac{\partial C_{$cmp$}}{\partial x}) +r_$cmp$ = 0
$$
\end



Thene whenever I call macro like this

<<pellet B>>   or like <<pellet O2>>
Then it inserts the diffusion-reaction BVP!



 

If I use LaTeX, I would perhaps do something like:
\begin{theorem}
\input{tid-thm-a}
\end{theorem}

How do I make it behave similar to LaTeX? Any help is appreciated. 

Pak

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/7929ebb9-5925-4a21-8a8f-05bc9d149a8en%40googlegroups.com.

Mohammad Rahmani

unread,
Jun 6, 2021, 10:58:46 AM6/6/21
to tiddl...@googlegroups.com
Pak,

I got your point you like the first like of tid appears as span e.g inline block NOT a div!


On Sun, Jun 6, 2021 at 5:26 PM Pak <pack...@gmail.com> wrote:
Hello,

I would like to imitate a latex environment using list widget and transclude the contents in the tiddlers.

Suppose I have 3 tiddlers: tid-thm-a, tid-thm-b, tid-thm-c I would like to transclude them in a tiddler so that it displays the following:

Theorem 1. (optional caption) (...contents in tid-thm-a... displayed in block mode, but the first line should be on the same line as Theorem 1}

move the first line into a field called summary or description or like that, then
<$view field=summary/>

NOTE that the transclude widget is called using block mode!


 

Theorem 2. (optional caption) (...contents in tid-thm-b... displayed in block mode, but the first line should be on the same line as Theorem 2}

Theorem 3. (optional caption) (...contents in tid-thm-c... displayed in block mode, but the first line should be on the same line as Theorem 3}

My initial attempt is

<$list filter="tid-thm-a tid-thm-b tid-thm-c">
Theorem x. (<$view field=caption/>) <$transclude mode="block"/>
</$list>

But there are two problems.
1. How do I make x run as a counter?
2. The contents of transcluded tiddlers appear on the next line, not after the word Theorem x.

If I use LaTeX, I would perhaps do something like:
\begin{theorem}
\input{tid-thm-a}
\end{theorem}

How do I make it behave similar to LaTeX? Any help is appreciated. 

Pak

--

Eric Shulman

unread,
Jun 6, 2021, 12:16:05 PM6/6/21
to TiddlyWiki
On Sunday, June 6, 2021 at 5:56:54 AM UTC-7 Pak wrote:
Suppose I have 3 tiddlers: tid-thm-a, tid-thm-b, tid-thm-c I would like to transclude them in a tiddler so that it displays the following:
Theorem 1. (optional caption) (...contents in tid-thm-a... displayed in block mode, but the first line should be on the same line as Theorem 1}
Theorem 2. (optional caption) (...contents in tid-thm-b... displayed in block mode, but the first line should be on the same line as Theorem 2}
Theorem 3. (optional caption) (...contents in tid-thm-c... displayed in block mode, but the first line should be on the same line as Theorem 3}

1. How do I make x run as a counter?
2. The contents of transcluded tiddlers appear on the next line, not after the word Theorem x.


Give this a try:
<style>
.theorems
   { counter-reset: num; }
.theorem::before
   { counter-increment: num; content: "Theorem " counter(num) "."; }
</style>
<div class="theorems">
   <$list filter="tid-thm-a tid-thm-b tid-thm-c">
      <div class="theorem">
         <$view field=caption/>
         <blockquote><$transclude mode="block"/></blockquote>
      </div>
   </$list>
</div>

Notes:
* The "theorems" class resets the counter named "num" to 0
* The "theorem" class increments the num counter and displays the "Theorem X." text
* I put the transcluded content within a blockquote just to make it look nicer

enjoy,
-e

Eric Shulman

unread,
Jun 6, 2021, 7:39:11 PM6/6/21
to TiddlyWiki
On Sunday, June 6, 2021 at 9:16:05 AM UTC-7 Eric Shulman wrote:
On Sunday, June 6, 2021 at 5:56:54 AM UTC-7 Pak wrote:
Suppose I have 3 tiddlers: tid-thm-a, tid-thm-b, tid-thm-c I would like to transclude them in a tiddler so that it displays the following:
Theorem 1. (optional caption) (...contents in tid-thm-a... displayed in block mode, but the first line should be on the same line as Theorem 1}
Theorem 2. (optional caption) (...contents in tid-thm-b... displayed in block mode, but the first line should be on the same line as Theorem 2}
Theorem 3. (optional caption) (...contents in tid-thm-c... displayed in block mode, but the first line should be on the same line as Theorem 3}

Addendum: I re-read the description of your desired layout.  My previous solution didn't put the tiddler contents on the same line as the "Theorem X."  heading.

Here's an updated solution that achieves the layout you described:

<style>
.theorems
   { counter-reset: num; }
.theorem::before
   { counter-increment: num; content: "Theorem " counter(num) "."; float:left; }
</style>
<div class="theorems">
   <$list filter="tid-thm-a tid-thm-b tid-thm-c">
      <div class="theorem">
         <span style="float:left;padding:0 0.5em;">(<$view field=caption/>)</span> <$transclude mode="block"/>
      </div>
      <div style="clear:both;"></div>
   </$list>
</div>

Notes:
* Added "float:left;" to the "theorem" class, so that it will appear before the caption text
* Added "float:left;padding:0 0.5em" around the caption text so that it will appear before the tiddler content
* Use of these two floats allows the first line of the tiddler content to appear on the same line as the "Theorem X." heading

Pak

unread,
Jun 6, 2021, 11:09:42 PM6/6/21
to TiddlyWiki
Hi Mohammad,

Thanks for the tip on macro+KaTeX, I didn't realize we can do that. This will be useful!



On Monday, June 7, 2021 at 6:39:11 AM UTC+7 Eric Shulman wrote:

<style>
.theorems
   { counter-reset: num; }
.theorem::before
   { counter-increment: num; content: "Theorem " counter(num) "."; float:left; }
</style>
<div class="theorems">
   <$list filter="tid-thm-a tid-thm-b tid-thm-c">
      <div class="theorem">
         <span style="float:left;padding:0 0.5em;">(<$view field=caption/>)</span> <$transclude mode="block"/>
      </div>
      <div style="clear:both;"></div>
   </$list>
</div>

Notes:
* Added "float:left;" to the "theorem" class, so that it will appear before the caption text
* Added "float:left;padding:0 0.5em" around the caption text so that it will appear before the tiddler content
* Use of these two floats allows the first line of the tiddler content to appear on the same line as the "Theorem X." heading


Hi Eric. Wow this works like a charm! The float trick and the custom counter are what I learned today.  Also, if I do something like this

.theorem::before
   { counter-increment: num; content: "Theorem 1." counter(num) "."; float:left; }

Then it will produce Theorem 1.1, Theorem 1.2, Theorem 1.3, ...
This is great! Many thanks :)

Pak
Reply all
Reply to author
Forward
0 new messages