[system] / branches / rel-2-3-dev / webwork-modperl / lib / WeBWorK / ContentGenerator / EquationDisplay.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-3-dev/webwork-modperl/lib/WeBWorK/ContentGenerator/EquationDisplay.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1841 Revision 1874
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/EquationDisplay.pm,v 1.1 2004/02/03 01:22:00 gage Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/EquationDisplay.pm,v 1.2 2004/03/04 21:05:54 sh002i Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
14# Artistic License for more details. 14# Artistic License for more details.
15################################################################################ 15################################################################################
16 16
17package WeBWorK::ContentGenerator::EquationDisplay; 17package WeBWorK::ContentGenerator::EquationDisplay;
18use base qw(WeBWorK::ContentGenerator); 18use base qw(WeBWorK::ContentGenerator);
19use WeBWorK::PG::ImageGenerator; 19
20=head1 NAME 20=head1 NAME
21 21
22 22
23WeBWorK::ContentGenerator::EquationDisplay -- create .png version of TeX equations. 23WeBWorK::ContentGenerator::EquationDisplay -- create .png version of TeX equations.
24 24
25=cut 25=cut
26 26
27# *** feedback should be exempt from authentication, so that people can send
28# feedback from the login page!
29
30use strict; 27use strict;
31use warnings; 28use warnings;
32use Data::Dumper;
33use CGI qw(); 29use CGI qw();
34use Mail::Sender; 30use WeBWorK::PG::ImageGenerator;
35use Text::Wrap qw(wrap);
36 31
37# request paramaters used 32sub display_equation {
38# 33 my ($self, $str) = @_;
39# user 34
40# key 35 my $imageTag = $self->{image_gen}->add($str, 'inline');
41# module 36 $self->{image_gen}->render();
42# set (if from ProblemSet or Problem) 37 return $imageTag;
43# problem (if from Problem) 38}
44# displayMode (if from Problem)
45# showOldAnswers (if from Problem)
46# showCorrectAnswers (if from Problem)
47# showHints (if from Problem)
48# showSolutions (if from Problem)
49 39
50# state data sent 40################################################################################
51# 41# template escape handlers
52# user object for current user 42################################################################################
53# permission level of current user 43
54# current session key
55# which ContentGenerator module called Feedback?
56# set object for current set (if from ProblemSet or Problem)
57# problem object for current problem (if from Problem)
58# display options (if from Problem)
59sub initialize { 44sub initialize {
60 my ($self) = @_; 45 my ($self) = @_;
61 my $r = $self->{r}; 46 my $r = $self->r;
62 my $ce = $self->{ce}; 47 my $ce = $r->ce;
63 my $db = $self->{db}; 48
64 my $envir = $ce->{envir};
65 $self->{image_gen} = WeBWorK::PG::ImageGenerator->new( 49 $self->{image_gen} = WeBWorK::PG::ImageGenerator->new(
66 tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir 50 tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir
67 latex => $ce->{externalPrograms}->{latex}, 51 latex => $ce->{externalPrograms}->{latex},
68 dvipng => $ce->{externalPrograms}->{dvipng}, 52 dvipng => $ce->{externalPrograms}->{dvipng},
69 useCache => 1, 53 useCache => 1,
70 cacheDir => $ce->{webworkDirs}->{equationCache}, 54 cacheDir => $ce->{webworkDirs}->{equationCache},
71 cacheURL => $ce->{webworkURLs}->{equationCache}, 55 cacheURL => $ce->{webworkURLs}->{equationCache},
72 cacheDB => $ce->{webworkFiles}->{equationCacheDB}, 56 cacheDB => $ce->{webworkFiles}->{equationCacheDB},
73 ); 57 );
58
74 my $equationStr = $r->param('eq'); 59 my $equationStr = $r->param('eq');
75 $self->{equationStr} = $equationStr if defined $equationStr; 60 $self->{equationStr} = $equationStr if defined $equationStr;
76 $self->{typesetStr} = $self->display_equation($equationStr) if $equationStr; 61 $self->{typesetStr} = $self->display_equation($equationStr) if $equationStr;
77
78
79}
80sub display_equation {
81 my $self = shift;
82 my $str = shift;
83 my $imageTag = $self->{image_gen}->add($str,'inline');
84 $self->{image_gen}->render();
85 return $imageTag;
86}
87sub path {
88 my ($self, $args) = @_;
89
90 my $ce = $self->{ce};
91 my $root = $ce->{webworkURLs}->{root};
92 my $courseName = $ce->{courseName};
93 return $self->pathMacro($args,
94 "Home" => "$root",
95 $courseName => "$root/$courseName",
96 "Feedback" => "",
97 );
98} 62}
99 63
64#sub path {
65# my ($self, $args) = @_;
66#
67# my $ce = $self->{ce};
68# my $root = $ce->{webworkURLs}->{root};
69# my $courseName = $ce->{courseName};
70# return $self->pathMacro($args,
71# "Home" => "$root",
72# $courseName => "$root/$courseName",
73# "Feedback" => "",
74# );
75#}
76#
100sub title { 77#sub title {
101 return "Equation"; 78# return "Equation";
102} 79#}
103 80
104sub body { 81sub body {
105 my $self = shift; 82 my ($self) = @_;
106 my $r = $self->{r}; 83 my $r = $self->r;
107 my $ce = $self->{ce};
108 my $db = $self->{db};
109 84
110
111 ####################################### 85 #######################################
112 # Initial data for the textarea field where the equation is entered 86 # Initial data for the textarea field where the equation is entered
113 ####################################### 87 #######################################
114 my $initial_str = "Enter equation here"; 88 my $initial_str = "Enter equation here";
115 $initial_str = $r->param('eq') if $self->{equationStr}; 89 $initial_str = $r->param('eq') if $self->{equationStr};
127 #### add the host name to the string 101 #### add the host name to the string
128 my $hostName = $r->hostname; 102 my $hostName = $r->hostname;
129 my $port = $r->get_server_port; 103 my $port = $r->get_server_port;
130 $hostName .= ":$port"; 104 $hostName .= ":$port";
131 $typesetStr =~ s|src="|src="http://$hostName|; 105 $typesetStr =~ s|src="|src="http://$hostName|;
106
132 my $typeset2Str = $typesetStr; 107 my $typeset2Str = $typesetStr;
133 $typeset2Str =~ s/</&lt;/g; 108 $typeset2Str =~ s/</&lt;/g;
134 $typeset2Str =~ s/>/&gt;/g; 109 $typeset2Str =~ s/>/&gt;/g;
110
135 my $sourceHref = $typesetStr; 111 my $sourceHref = $typesetStr;
136 $sourceHref =~ /"([^"]*)"/; 112 $sourceHref =~ /"([^"]*)"/;
137 $sourceHref = $1; 113 $sourceHref = $1;
138 114
139 ####################################### 115 #######################################
140 # Print the page 116 # Print the page
141 ####################################### 117 #######################################
118 return join( "",
142 return join( "", "Copy the location of this image (or drag and drop) into your editing area:", 119 "Copy the location of this image (or drag and drop) into your editing area:",
143 CGI::br(), 120 CGI::br(),
144 $typeset2Str, 121 $typeset2Str,
145 CGI::br(), 122 CGI::br(),
146 $typesetStr, 123 $typesetStr,
147 CGI::start_form(-method=>'POST',-action=>$r->uri), 124 CGI::start_form(-method=>'POST', -action=>$r->uri),
148 $self->hidden_authen_fields, 125 $self->hidden_authen_fields,
149 CGI::textarea( "eq",$initial_str,5,40), 126 CGI::textarea( "eq", $initial_str, 5, 40),
150 CGI::submit('typeset','typeset'), 127 CGI::submit('typeset', 'typeset'),
151
152 CGI::end_form(), 128 CGI::end_form(),
153 ) 129 );
154}
155
156
157
158sub hidden_state_fields($) {
159 my $self = shift;
160 my $r = $self->{r};
161
162 print CGI::hidden("$_", $r->param("$_"))
163 foreach (qw(module set problem displayMode showOldAnswers
164 showCorrectAnswers showHints showSolutions));
165} 130}
166 131
1671; 1321;

Legend:
Removed from v.1841  
changed lines
  Added in v.1874

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9