Quantcast

[Jlatexmath] Dynamic/animated LaTeX typesetting

classic Classic list List threaded Threaded
5 messages Options
Christian Stussak-2 Christian Stussak-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Jlatexmath] Dynamic/animated LaTeX typesetting

Finally, after thinking about how I would implement dynamic typesetting in JLaTeXMath I revisited the jlatexmath.dynamic classes and found out that it is actually implemented exactly like this. Use the command \jlmDynamic{key} where "key" is the key in your database of strings to replace. You have to register an ExternalConverterFactory at the jlatexmath.dynamic.DynamicAtom class. This factory constructs an ExternalConverter which has a single method:

public String getLaTeXString(String externalCode);

That's where the key becomes important. I implemented the ExternalConverter to store a map internally. It looks up a value for "key" which I can set dynamically in my program. Now you can create a TeXFormula once, containing the jlmDynamic command. Every time you create a TeXIcon from the TeXFormula the jlmDynamic placeholder is updated with the LaTeX code stored as the value of "key" in the database of ExternalConverter.

Pretty easy and straight forward, actually.
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Phuc Luoi Phuc Luoi
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Dynamic/animated LaTeX typesetting

Interesting,
Thanks for your share. I will look into it to day. Maybe it can improve the performance my program.

On Fri, Sep 21, 2012 at 11:26 PM, Christian Stussak <[hidden email]> wrote:
Finally, after thinking about how I would implement dynamic typesetting in JLaTeXMath I revisited the jlatexmath.dynamic classes and found out that it is actually implemented exactly like this. Use the command \jlmDynamic{key} where "key" is the key in your database of strings to replace. You have to register an ExternalConverterFactory at the jlatexmath.dynamic.DynamicAtom class. This factory constructs an ExternalConverter which has a single method:

public String getLaTeXString(String externalCode);

That's where the key becomes important. I implemented the ExternalConverter to store a map internally. It looks up a value for "key" which I can set dynamically in my program. Now you can create a TeXFormula once, containing the jlmDynamic command. Every time you create a TeXIcon from the TeXFormula the jlmDynamic placeholder is updated with the LaTeX code stored as the value of "key" in the database of ExternalConverter.

Pretty easy and straight forward, actually.
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Calixte DENIZET Calixte DENIZET
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Dynamic/animated LaTeX typesetting

Hi all,

Initially I developped this feature to avoid to parse again and again a formula which contains dynamic data, for example:

tf = new TeXFormula("\\frac{\\pi}{\\jlmDynamic{$length(foo)+$sin(bar)}}"); // formula is parsed and transformed in a set of Atoms
icon = tf.createTeXIcon(..);
icon.paintIcon(...); // each Atom is transformed in a Box and this box is drawn

if $length(foo)+$sin(bar) is an expression from an external language (initially developped for Geogebra), the external converter must evaluate this expression and return a LaTeX expression. Each time the icon is redrawn, when the painter is on a DynamicAtom the associated box is regenerated according to the contents returned by the converter.

That avoids such syntax:
tf = new TeXFormula("\\frac{\\pi}{" + eval("$length(foo) +$sin(bar)").LaTeXify() + "}");
icon = tf.createTeXIcon(..);
icon.paintIcon(...);

For your your information, I added a cache system to avoid to generate again and again an icon or a TeXFormula (class org.scilab.forge.jlatexmath.cache.JLaTexMathCache).

You could grep the Geogebra sources to find examples.

Best regards

Calixte


On 22/09/2012 13:08, Phuc Luoi wrote:
Interesting,
Thanks for your share. I will look into it to day. Maybe it can improve the performance my program.

On Fri, Sep 21, 2012 at 11:26 PM, Christian Stussak <[hidden email]> wrote:
Finally, after thinking about how I would implement dynamic typesetting in JLaTeXMath I revisited the jlatexmath.dynamic classes and found out that it is actually implemented exactly like this. Use the command \jlmDynamic{key} where "key" is the key in your database of strings to replace. You have to register an ExternalConverterFactory at the jlatexmath.dynamic.DynamicAtom class. This factory constructs an ExternalConverter which has a single method:

public String getLaTeXString(String externalCode);

That's where the key becomes important. I implemented the ExternalConverter to store a map internally. It looks up a value for "key" which I can set dynamically in my program. Now you can create a TeXFormula once, containing the jlmDynamic command. Every time you create a TeXIcon from the TeXFormula the jlmDynamic placeholder is updated with the LaTeX code stored as the value of "key" in the database of ExternalConverter.

Pretty easy and straight forward, actually.
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath



_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


-- 
Calixte Denizet
Software Development Engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
http://www.scilab-enterprises.com

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Christian Stussak-2 Christian Stussak-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Dynamic/animated LaTeX typesetting

Would you mind to share a small example of how to use the cache? 


Am 22.09.2012 um 15:10 schrieb Calixte Denizet:

Hi all,

Initially I developped this feature to avoid to parse again and again a formula which contains dynamic data, for example:

tf = new TeXFormula("\\frac{\\pi}{\\jlmDynamic{$length(foo)+$sin(bar)}}"); // formula is parsed and transformed in a set of Atoms
icon = tf.createTeXIcon(..);
icon.paintIcon(...); // each Atom is transformed in a Box and this box is drawn

if $length(foo)+$sin(bar) is an expression from an external language (initially developped for Geogebra), the external converter must evaluate this expression and return a LaTeX expression. Each time the icon is redrawn, when the painter is on a DynamicAtom the associated box is regenerated according to the contents returned by the converter.

That avoids such syntax:
tf = new TeXFormula("\\frac{\\pi}{" + eval("$length(foo) +$sin(bar)").LaTeXify() + "}");
icon = tf.createTeXIcon(..);
icon.paintIcon(...);

For your your information, I added a cache system to avoid to generate again and again an icon or a TeXFormula (class org.scilab.forge.jlatexmath.cache.JLaTexMathCache).

You could grep the Geogebra sources to find examples.

Best regards

Calixte


On 22/09/2012 13:08, Phuc Luoi wrote:
Interesting,
Thanks for your share. I will look into it to day. Maybe it can improve the performance my program.

On Fri, Sep 21, 2012 at 11:26 PM, Christian Stussak <[hidden email]> wrote:
Finally, after thinking about how I would implement dynamic typesetting in JLaTeXMath I revisited the jlatexmath.dynamic classes and found out that it is actually implemented exactly like this. Use the command \jlmDynamic{key} where "key" is the key in your database of strings to replace. You have to register an ExternalConverterFactory at the jlatexmath.dynamic.DynamicAtom class. This factory constructs an ExternalConverter which has a single method:

public String getLaTeXString(String externalCode);

That's where the key becomes important. I implemented the ExternalConverter to store a map internally. It looks up a value for "key" which I can set dynamically in my program. Now you can create a TeXFormula once, containing the jlmDynamic command. Every time you create a TeXIcon from the TeXFormula the jlmDynamic placeholder is updated with the LaTeX code stored as the value of "key" in the database of ExternalConverter.

Pretty easy and straight forward, actually.
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath



_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


-- 
Calixte Denizet
Software Development Engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
http://www.scilab-enterprises.com
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Calixte DENIZET Calixte DENIZET
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Dynamic/animated LaTeX typesetting

The main functions (static) are:

setMaxCachedObjects(int max)
Object getCachedTeXFormula(String f, int style, int type, int size, int inset, Color fgcolor)
Object paintCachedTeXFormula(Object o, Graphics2D g)

The first one set the cache max size.

The second one return a key corresponding to a cached formula given by the String f (the other argument are the same as in TeXFormula.createTeXIcon). The key is built with the 6 arguments of getCachedTeXFormula. These 6 values are used to identify the key.

And the third one is used to paint the cached image (a BufferedImage) in using the key returned by getCachedTeXFormula. If the corresponding image has been removed from the cache, then it will be regenerated according to the informations saved in the key.

If the position of the formula should change, you just have to translate your Graphics2D. But if you need to rescale (more generally when the determinant of the current AffineTrnasform of your Graphisc2D is different of 1) the Graphics2D, you 'll need to clear the cache with clearCache() (or you can remove a key from the cache in using removeCachedTeXFormula(Object o)).

If you need to have the dimensions of the cached object you can use getCachedTeXFormulaDimensions(Object o) which return a 3-array containing width, height and depth.

Object key = JLaTeXMathCache.getCachedTeXFormula("\\frac{\\pi}{4}", TeXConstants.STYLE_DISPLAY, TeXFormula.SANSSERIF, 12, 2, Color.WHITE);
for (int i = 0; i < 100; i++) {
   g2d.translate(10, 10);
   key = JLaTeXMathCache.paintCachedTeXFormula(key, g2d);
}

The cache is based on SoftReference objects, so it is possible that a cached image is removed, in this case the info containing in the key object are used to regenerate the image.

You can have a look on the source code here (one file):
http://forge.scilab.org/index.php/p/jlatexmath/source/tree/master/src/org/scilab/forge/jlatexmath/cache/JLaTeXMathCache.java

Best regards

Calixte


On 22/09/2012 16:05, Christian Stussak wrote:
Would you mind to share a small example of how to use the cache? 


Am 22.09.2012 um 15:10 schrieb Calixte Denizet:

Hi all,

Initially I developped this feature to avoid to parse again and again a formula which contains dynamic data, for example:

tf = new TeXFormula("\\frac{\\pi}{\\jlmDynamic{$length(foo)+$sin(bar)}}"); // formula is parsed and transformed in a set of Atoms
icon = tf.createTeXIcon(..);
icon.paintIcon(...); // each Atom is transformed in a Box and this box is drawn

if $length(foo)+$sin(bar) is an expression from an external language (initially developped for Geogebra), the external converter must evaluate this expression and return a LaTeX expression. Each time the icon is redrawn, when the painter is on a DynamicAtom the associated box is regenerated according to the contents returned by the converter.

That avoids such syntax:
tf = new TeXFormula("\\frac{\\pi}{" + eval("$length(foo) +$sin(bar)").LaTeXify() + "}");
icon = tf.createTeXIcon(..);
icon.paintIcon(...);

For your your information, I added a cache system to avoid to generate again and again an icon or a TeXFormula (class org.scilab.forge.jlatexmath.cache.JLaTexMathCache).

You could grep the Geogebra sources to find examples.

Best regards

Calixte


On 22/09/2012 13:08, Phuc Luoi wrote:
Interesting,
Thanks for your share. I will look into it to day. Maybe it can improve the performance my program.

On Fri, Sep 21, 2012 at 11:26 PM, Christian Stussak <[hidden email]> wrote:
Finally, after thinking about how I would implement dynamic typesetting in JLaTeXMath I revisited the jlatexmath.dynamic classes and found out that it is actually implemented exactly like this. Use the command \jlmDynamic{key} where "key" is the key in your database of strings to replace. You have to register an ExternalConverterFactory at the jlatexmath.dynamic.DynamicAtom class. This factory constructs an ExternalConverter which has a single method:

public String getLaTeXString(String externalCode);

That's where the key becomes important. I implemented the ExternalConverter to store a map internally. It looks up a value for "key" which I can set dynamically in my program. Now you can create a TeXFormula once, containing the jlmDynamic command. Every time you create a TeXIcon from the TeXFormula the jlmDynamic placeholder is updated with the LaTeX code stored as the value of "key" in the database of ExternalConverter.

Pretty easy and straight forward, actually.
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath



_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


-- 
Calixte Denizet
Software Development Engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
http://www.scilab-enterprises.com
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath



_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath


-- 
Calixte Denizet
Software Development Engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
http://www.scilab-enterprises.com

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Loading...