--- loncom/homework/structuretags.pm 2011/12/26 13:45:10 1.497.2.5 +++ loncom/homework/structuretags.pm 2011/12/27 19:48:31 1.497.2.6 @@ -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::lonlocal; 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 @@ sub select_hyphenation { } } ## +# 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 @@ sub start_problem { } } elsif ($target eq 'tex') { $result .= 'INSERTTEXFRONTMATTERHERE'; + $result .= &select_metadata_hyphenation(); + } } elsif ($target eq 'edit') { @@ -1799,6 +1824,7 @@ sub end_languageblock { $result = &select_hyphenation($which); } $result .= $available_texts{$which}; + $result .= &select_metadata_hyphenation(); # Restore original language. } undef(%available_texts); &Apache::lonxml::deregister('Apache::structuretags',('lang'));