[tw] Re: Defining LaTeX macros or text-substitution in general?

2017-07-16 Thread 'Mark S.' via TiddlyWiki
Hello Tom,

I guess you get around the $$ problem by not putting two symbols right next 
to each other, which latex allows ??

For your first question below, I think I need an explainer on making new 
commands in Latex. I think even I was using it I never needed to roll my 
own (or wasn't that advanced). 

For the second question, go into your plugins in settings, turn off the 
Katex/Latex plugin. Save and reload. Now your formula will show up as Latex 
markup ready to copy and paste into your Latex application.

If you don't want to turn your plugin off, you could also copy your text 
and macro into any TW (tiddlywiki.com is handy) and your text will be 
rendered just as Latex markup. You could have a standard non-Latex TW 
around with your Latex macros for whenever want to see just the markup.

Good luck!
Mark

On Sunday, July 16, 2017 at 7:41:04 PM UTC-7, Tom wrote:
>
> Thanks, this is very useful!
> I played around with this a little and found that there is actually no 
> need to change the code of Katex. It is much better to use the <$latex> 
> commands that Katex provides. There is a small issue that I actually found 
> to be a benefit. Namely, Katex uses $$ syntax for both inline and displayed 
> equations, which one it uses depends on whether there are any linebreaks. 
> However, I prefer to have a choice (sometimes inline equations tend to be 
> long so that it is better to write them on multiple lines). Here are my 
> commands:
> \define tx(text:"",displayMode:"false",
>   var1:"\overline{X}",
>   R:"\mathbb{R}",
>   partition:"\mathcal{P}"
> )
>   <$latex text="$text$" displayMode="$displayMode$">
> \end
> \define tex(text:"") 
>   <>
> \end
> So, <> is an inline equation whereas <> 
> is a displayed equation, regardless of whether there are any linebreaks.
>
> I also checked the number of variables that the approach supports and 
> there were absolutely no problems with twenty variables, which is enough 
> for me (for one project).
>
> There are still a few things that I would prefer to improve upon. First, 
> it would be nice to be able to define commands with arguments. For example, 
> in LaTeX I like to define \newcommand{\pd}[2][]{\frac{\partial #1}{\partial 
> {#2}}}, so that $\pd{f(x,y)}{x}$ is the partial derivative of $f$ wrt $x$. 
> Second, it would be excellent to be able to redefine the command syntax, so 
> that I could copy the text between tiddlyWiki and LaTeX. Any ideas?
> Best regards,
> Tom
>
> On Sunday, July 16, 2017 at 2:34:29 AM UTC+2, Mark S. wrote:
>>
>> This is a little discussion about a method that might get you at least 
>> closer to where you want.
>>
>> The problem with the implementation of Katex on TW5 is the choice of $$ 
>> to indicate latex is about to begin. This causes all sorts of havoc with 
>> the TW macros, because TW macros use $ and $( to indicate the start of a 
>> parameter. But, if you make a couple very tiny changes to the Katex plugin, 
>> you could use, for instance, %% to indicate the start of latex formatting.
>>
>> Once you make this change, you can then write a macro like this:
>>
>> \define latex(text:"",pi:"\pi",xi:"\xi",infty:"\infty",int:"\int",hat:
>> "\hat")
>> %%
>> $text$
>> %%
>> \endEnter code here...
>>
>> In this example, I've only applied definitions for 5 latex symbols. I 
>> don't know if there is an upper limit to symbol parameters that can be 
>> created in this way. I guess this would be an interesting way to find out 
>> ;-)
>>
>> You then invoke this using the $symbol$ syntax of TW, like:
>>
>> <> $xi$ x}\,d$xi$"""  >>
>>
>> This produces:
>>
>>
>>
>> Now let's say you want to change the definition of pie on the fly. You 
>> can do it like this:
>>
>>
>> <> $xi$ x}\,d$xi$""" pi:"YUM" >>
>>
>> which produces (I hope these images show up) :
>>
>>
>>
>> You can also change the default definition everywhere just by changing 
>> the latex macro default parameter for PI.
>>
>> So, that's my idea. Something to think about.
>>
>> Mark
>>
>> On Saturday, July 15, 2017 at 5:44:45 AM UTC-7, Tom wrote:
>>>
>>> Hi,
>>> I'm relatively new to tiddlywiki, but I find it extremely useful and 
>>> have moved my research notes to TW. 
>>>
>>> There is one thing that would make my life much easier: I would like to 
>>> define global LaTeX macros, say \elasticity to correspond to \varepsilon, 
>>> so that every time I use it in a formula, it would get replace before KaTeX 
>>> displays it. Looking at the forums, I see that other people have had a 
>>> similar question, but no solution yet. Since it seems that TW has a 
>>> built-in macro support, it should not be that difficult to extend it just a 
>>> bit. A simple text substitution (whenever I write TW replace it with 
>>> tiddlywiki) should do the trick.
>>>
>>> Just to clarify the importance: in research it is often very useful to 
>>> use macros for variable names, because if the notation changes in the later 
>>> stages, there is no need to go through everything and change say 
>>> \vareps

[tw] Re: Defining LaTeX macros or text-substitution in general?

2017-07-16 Thread Tom
Thanks, this is very useful!
I played around with this a little and found that there is actually no need 
to change the code of Katex. It is much better to use the <$latex> commands 
that Katex provides. There is a small issue that I actually found to be a 
benefit. Namely, Katex uses $$ syntax for both inline and displayed 
equations, which one it uses depends on whether there are any linebreaks. 
However, I prefer to have a choice (sometimes inline equations tend to be 
long so that it is better to write them on multiple lines). Here are my 
commands:
\define tx(text:"",displayMode:"false",
  var1:"\overline{X}",
  R:"\mathbb{R}",
  partition:"\mathcal{P}"
)
  <$latex text="$text$" displayMode="$displayMode$">
\end
\define tex(text:"") 
  <>
\end
So, <> is an inline equation whereas <> is 
a displayed equation, regardless of whether there are any linebreaks.

I also checked the number of variables that the approach supports and there 
were absolutely no problems with twenty variables, which is enough for me 
(for one project).

There are still a few things that I would prefer to improve upon. First, it 
would be nice to be able to define commands with arguments. For example, in 
LaTeX I like to define \newcommand{\pd}[2][]{\frac{\partial #1}{\partial 
{#2}}}, so that $\pd{f(x,y)}{x}$ is the partial derivative of $f$ wrt $x$. 
Second, it would be excellent to be able to redefine the command syntax, so 
that I could copy the text between tiddlyWiki and LaTeX. Any ideas?
Best regards,
Tom

On Sunday, July 16, 2017 at 2:34:29 AM UTC+2, Mark S. wrote:
>
> This is a little discussion about a method that might get you at least 
> closer to where you want.
>
> The problem with the implementation of Katex on TW5 is the choice of $$ to 
> indicate latex is about to begin. This causes all sorts of havoc with the 
> TW macros, because TW macros use $ and $( to indicate the start of a 
> parameter. But, if you make a couple very tiny changes to the Katex plugin, 
> you could use, for instance, %% to indicate the start of latex formatting.
>
> Once you make this change, you can then write a macro like this:
>
> \define latex(text:"",pi:"\pi",xi:"\xi",infty:"\infty",int:"\int",hat:
> "\hat")
> %%
> $text$
> %%
> \endEnter code here...
>
> In this example, I've only applied definitions for 5 latex symbols. I 
> don't know if there is an upper limit to symbol parameters that can be 
> created in this way. I guess this would be an interesting way to find out 
> ;-)
>
> You then invoke this using the $symbol$ syntax of TW, like:
>
> < x}\,d$xi$"""  >>
>
> This produces:
>
>
>
> Now let's say you want to change the definition of pie on the fly. You can 
> do it like this:
>
>
> < x}\,d$xi$""" pi:"YUM" >>
>
> which produces (I hope these images show up) :
>
>
>
> You can also change the default definition everywhere just by changing the 
> latex macro default parameter for PI.
>
> So, that's my idea. Something to think about.
>
> Mark
>
> On Saturday, July 15, 2017 at 5:44:45 AM UTC-7, Tom wrote:
>>
>> Hi,
>> I'm relatively new to tiddlywiki, but I find it extremely useful and have 
>> moved my research notes to TW. 
>>
>> There is one thing that would make my life much easier: I would like to 
>> define global LaTeX macros, say \elasticity to correspond to \varepsilon, 
>> so that every time I use it in a formula, it would get replace before KaTeX 
>> displays it. Looking at the forums, I see that other people have had a 
>> similar question, but no solution yet. Since it seems that TW has a 
>> built-in macro support, it should not be that difficult to extend it just a 
>> bit. A simple text substitution (whenever I write TW replace it with 
>> tiddlywiki) should do the trick.
>>
>> Just to clarify the importance: in research it is often very useful to 
>> use macros for variable names, because if the notation changes in the later 
>> stages, there is no need to go through everything and change say 
>> \varepsilon to e. It would be also useful to define macros as shortcuts, of 
>> course.
>> Best regards,
>> Tom
>>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/e083afb5-50fb-42db-ba07-3215eb10a7e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] Re: Defining LaTeX macros or text-substitution in general?

2017-07-15 Thread 'Mark S.' via TiddlyWiki
This is a little discussion about a method that might get you at least 
closer to where you want.

The problem with the implementation of Katex on TW5 is the choice of $$ to 
indicate latex is about to begin. This causes all sorts of havoc with the 
TW macros, because TW macros use $ and $( to indicate the start of a 
parameter. But, if you make a couple very tiny changes to the Katex plugin, 
you could use, for instance, %% to indicate the start of latex formatting.

Once you make this change, you can then write a macro like this:

\define latex(text:"",pi:"\pi",xi:"\xi",infty:"\infty",int:"\int",hat:"\hat"
)
%%
$text$
%%
\endEnter code here...

In this example, I've only applied definitions for 5 latex symbols. I don't 
know if there is an upper limit to symbol parameters that can be created in 
this way. I guess this would be an interesting way to find out ;-)

You then invoke this using the $symbol$ syntax of TW, like:

<>

This produces:



Now let's say you want to change the definition of pie on the fly. You can 
do it like this:


<>

which produces (I hope these images show up) :



You can also change the default definition everywhere just by changing the 
latex macro default parameter for PI.

So, that's my idea. Something to think about.

Mark

On Saturday, July 15, 2017 at 5:44:45 AM UTC-7, Tom wrote:
>
> Hi,
> I'm relatively new to tiddlywiki, but I find it extremely useful and have 
> moved my research notes to TW. 
>
> There is one thing that would make my life much easier: I would like to 
> define global LaTeX macros, say \elasticity to correspond to \varepsilon, 
> so that every time I use it in a formula, it would get replace before KaTeX 
> displays it. Looking at the forums, I see that other people have had a 
> similar question, but no solution yet. Since it seems that TW has a 
> built-in macro support, it should not be that difficult to extend it just a 
> bit. A simple text substitution (whenever I write TW replace it with 
> tiddlywiki) should do the trick.
>
> Just to clarify the importance: in research it is often very useful to use 
> macros for variable names, because if the notation changes in the later 
> stages, there is no need to go through everything and change say 
> \varepsilon to e. It would be also useful to define macros as shortcuts, of 
> course.
> Best regards,
> Tom
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/7fabb4ed-3adf-4f7a-a885-40c3cfd0dd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.