Skip to content

Commit

Permalink
ttools: improve handling of LaTeX errors in plot axis labels
Browse files Browse the repository at this point in the history
Now writes the source text rather than the error message;
it tends to be more compact and long captions can cause trouble.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 6823aeb commit b7dfb55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions topcat/src/docs/sun253.xml
Expand Up @@ -18421,6 +18421,7 @@ introduced since the last version:
in the <label>Axes</label>-<label>Grid</label> tabs
of the various plot windows.</li>
<li>New experimental SAMP message <code>table.get.stil</code>.</li>
<li>Improve handling of LaTeX errors in axis labelling.</li>
</ul>
</p></dd>
</dl>
Expand Down
15 changes: 11 additions & 4 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/LatexCaptioner.java
Expand Up @@ -4,6 +4,8 @@
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.scilab.forge.jlatexmath.ParseException;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
Expand Down Expand Up @@ -35,6 +37,8 @@ public class LatexCaptioner implements Captioner {
public static final int TYPE_ROMAN = TeXFormula.ROMAN;
public static final int TYPE_TYPEWRITER = TeXFormula.TYPEWRITER;

private final Logger logger_ =
Logger.getLogger( "uk.ac.starlink.ttools.plot2" );
static {
// Avoids a warning. Don't think it does anything useful unless
// you're using FOP, but I'm not certain.
Expand Down Expand Up @@ -90,7 +94,9 @@ public void drawCaption( String label, Graphics g ) {
ti = createTeXIcon( label, g.getColor() );
}
catch ( ParseException e ) {
getErrorCaptioner().drawCaption( getErrorText( e ), g );
getErrorCaptioner().drawCaption( getErrorText( label, e ), g );
logger_.log( Level.WARNING, "Bad LaTeX: \"" + label + "\" ("
+ e.getMessage() + ")", e );
return;
}
Insets insets = ti.getInsets();
Expand All @@ -105,7 +111,7 @@ public Rectangle getCaptionBounds( String label ) {
}
catch ( ParseException e ) {
return getErrorCaptioner()
.getCaptionBounds( getErrorText( e ) );
.getCaptionBounds( getErrorText( label, e ) );
}
Insets insets = ti.getInsets();
Rectangle bounds =
Expand Down Expand Up @@ -147,11 +153,12 @@ private String adjustLabel( String label ) {
/**
* Text used as display in case of a LaTeX parse error.
*
* @param label input label text
* @param err latex parse error
* @retrun error message string
*/
private String getErrorText( ParseException err ) {
return "TeX Error: " + err.getMessage();
private String getErrorText( String label, ParseException err ) {
return "Bad TeX: " + label;
}

/**
Expand Down

0 comments on commit b7dfb55

Please sign in to comment.