[LON-CAPA-cvs] cvs: loncom(language_hyphenation) /homework structuretags.pm
foxr
foxr at source.lon-capa.org
Tue Dec 27 14:48:31 EST 2011
foxr Tue Dec 27 19:48:31 2011 EDT
Modified files: (Branch: language_hyphenation)
/loncom/homework structuretags.pm
Log:
BZ 6490
1. Start the LaTeX output with a \selectlanguage chosen from the
metadata 'language' for the resource.
2. After a translation has altered the selected rendering
language, restore it to the language implied by the metadata.
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.497.2.5 loncom/homework/structuretags.pm:1.497.2.6
--- loncom/homework/structuretags.pm:1.497.2.5 Mon Dec 26 13:45:10 2011
+++ loncom/homework/structuretags.pm Tue Dec 27 19:48:31 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.497.2.5 2011/12/26 13:45:10 foxr Exp $
+# $Id: structuretags.pm,v 1.497.2.6 2011/12/27 19:48:31 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,6 +61,7 @@
use Apache::lonxml;
use Apache::londefdef;
use Apache::lonenc();
+use Apache::loncommon();
use Time::HiRes qw( gettimeofday tv_interval );
use lib '/home/httpd/lib/perl/';
use LONCAPA;
@@ -110,6 +111,28 @@
}
}
##
+# Selects hyphenation based on the current problem metadata.
+# This requires that
+# - There is a language metadata item set for the problem.
+# - The language has a latex/babel hyphenation.
+#
+# @note: Uses &Apache::lonxml::request to locate the Uri associated with
+# this problem.
+# @return string (possibly empty).
+# @retval If not empty an appropriate \selectlanguage{} directive.
+#
+sub select_metadata_hyphenation {
+ my $uri = $Apache::lonxml::request->uri;
+ my $language = &Apache::lonnet::metadata($uri, 'language');
+ my $latex_language = &Apache::loncommon::latexhyphenation($language);
+ if ($latex_language) {
+ return '\selectlanguage{'.$latex_language."}\n";
+ }
+ return ''; # no latex hyphenation or no lang metadata.
+}
+
+
+##
# Clears the set of languages required by the document being rendered.
#
sub clear_required_languages {
@@ -1286,6 +1309,8 @@
}
} elsif ($target eq 'tex') {
$result .= 'INSERTTEXFRONTMATTERHERE';
+ $result .= &select_metadata_hyphenation();
+
}
} elsif ($target eq 'edit') {
@@ -1799,6 +1824,7 @@
$result = &select_hyphenation($which);
}
$result .= $available_texts{$which};
+ $result .= &select_metadata_hyphenation(); # Restore original language.
}
undef(%available_texts);
&Apache::lonxml::deregister('Apache::structuretags',('lang'));
More information about the LON-CAPA-cvs
mailing list