File: MuDimension.pm

package info (click to toggle)
latexml 0.8.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,920 kB
  • sloc: xml: 109,048; perl: 30,224; sh: 179; javascript: 28; makefile: 13
file content (100 lines) | stat: -rw-r--r-- 3,474 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# /=====================================================================\ #
# |  LaTeXML::Core::MuDimension                                         | #
# | Representation of Math Dimensions                                   | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Core::MuDimension;
use LaTeXML::Global;
use strict;
use warnings;
use LaTeXML::Common::Number;
use LaTeXML::Common::Dimension;
use base qw(LaTeXML::Common::Dimension);
use base qw(Exporter);
our @EXPORT = (qw(&MuDimension));

#======================================================================
# Exported constructor.
# Note that MuDimension is almost never used in TeX (there's no \newmudimen)

# Create a MuDimension given either a float with "mu" OR a number in scaled mu (NOT scaled points!)
sub MuDimension {
  my ($spec) = @_;
  return LaTeXML::Core::MuDimension->new($spec); }

sub _unit { return 'mu'; }

sub new {
  my ($class, $spec) = @_;
  $spec = "0" unless $spec;
  $spec = ToString($spec) if ref $spec;
  if ($spec =~ /^(-?\d*\.?\d*)mu$/) {    # mu given, convert to scaled mu
    return bless [fixpoint($1, $UNITY)], $class; }    # fake "mu" in sp
  else {
    # See comment in Dimension for why kround rather than int
    return bless [kround($spec || 0)], $class; } }

#======================================================================
sub stringify {
  my ($self) = @_;
  return "MuDimension[" . $$self[0] . "]"; }

# Note that $mu->valueOf will return scaled mu, NOT scaled pts;
# But in priniple these should never be combined with regular Dimensions/Glue
# TeX gives error "Incompatible glue units"
# HOWEVER, since we'll encounter mixtures of mu & pts when computing sizes,
# we're going to have to make sure we use the right scaling!
sub spValue {
  my ($self, $prec) = @_;
  return kround($$self[0] * $STATE->lookupValue('font')->getMUWidth / $UNITY); }

# A mu is 1/18th of an em in the current math font.
# 1 mu = 1em/18 = 10pt/18 = 5/9 pt; 1pt = 9/5mu = 1.8mu (for 10pt)
sub ptValue {
  my ($self, $prec) = @_;
  return roundto($$self[0] / $UNITY / 1.8, $prec); }

sub pxValue {
  my ($self, $prec) = @_;
  return roundto($$self[0] / $UNITY / 1.8 * ($STATE->lookupValue('DPI') || 100 / 72.27), $prec); }

#======================================================================
1;

__END__

=pod 

=head1 NAME

C<LaTeXML::Core::MuDimension> - representation of math dimensions;
extends L<LaTeXML::Common::Dimension>.

=head2 Exported functions

=over 4

=item C<< $mudimension = MuDimension($spec); >>

Creates a MuDimension object, similar to Dimension.
C<$spec> can be a string with a floating point number and "mu"
or just a number standing for scaled mu (ie. fixedpoint).

=back

=head1 AUTHOR

Bruce Miller <bruce.miller@nist.gov>

=head1 COPYRIGHT

Public domain software, produced as part of work done by the
United States Government & not subject to copyright in the US.

=cut