Drupal:Integrating Mathjax with Field Collections

109 views
Skip to first unread message

Jason Curley

unread,
Apr 13, 2012, 3:19:33 PM4/13/12
to mathja...@googlegroups.com

Hello,

I am new to this group and have been trying to figure out this problem for a few days now to no avail.

Mathjax renders LaTeX on my Drupal site for one dimensional content types, however, when I add the Field Collections module (allows for content type within a content type), the I get an server 500 error when trying to view any nodes of the type that includes Field Collections.

Essentially, when I create a Node of a content type that includes a Field Collection, I can save it and edit it, but I cannot view/preview it (500 error). Before installing MathJax, Field Collections worked perfectly as well.

I am hoping that there is an easy solution to this or at least someone that can point me in the right direction so that I can make LaTeX render properly for content types that include a field collection.

Thanks!

~Jason

P.S.  This scenario is very easy to duplicate on a (fresh) Drupal installation with only Mathjax and Field Collection modules installed.  Create a content type that includes a field collection and create a node.  View the node and 500 error occurs.

Jason Curley

unread,
Apr 13, 2012, 3:42:53 PM4/13/12
to mathja...@googlegroups.com
If nothing else, can anyone tell me how I might go about debugging this internal server 500 error I'm getting.  I have a dedicated host with root access.

~Jason

Peter Krautzberger

unread,
Apr 13, 2012, 4:09:28 PM4/13/12
to mathja...@googlegroups.com
Two quick thoughts:

a) how do you use MathJax in drupal? Are you using the module or have you added it manually? In any case, you could try the other option.

b) do you have access to the source of the page that does not render? Could you post it somewhere?


Peter.

Jason Curley

unread,
Apr 14, 2012, 10:20:22 AM4/14/12
to mathja...@googlegroups.com
Peter,

a) I am using the Drupal MathJax module right now.  The module works just fine as long as I am not using Field Collections.  Is installing it "manually" relatively easy to do?  I am willing to try anything... is there a how-to guide you recommend?

b)Unless I am missing something, there is no source produced on the blank (500 error) page when I click "view source". 

For what it's worth, Field Collections are really like having a content type within a content type.  I am using these field collections to build a content type called glossary term that has a list of examples attached to it among other things.  I suspect that a server side PHP script is causing the issue but cannot be sure.  Since the MathJax module for Drupal works on any linear content types that do not include Field Collections, I suspect that there is some conflict when the MathJax or Field Collections modules are trying to build the HTML page with PHP.  I am not sure how to debug this sort of problem myself.

Hopefully this helps, if there is any more information I can give you just let me know.  Thanks for the speedy reply, I hate being stuck!

~Jason

Peter Krautzberger

unread,
Apr 14, 2012, 10:41:00 AM4/14/12
to mathja...@googlegroups.com
I don't know much about Drupal, but in general, all you need for MathJax to work is to include the usual script in the header of your html.

So for example, instead of using the module, you could modify your theme and have it add


to the header of each page.

Peter.

Davide P. Cervone

unread,
Apr 14, 2012, 10:48:26 AM4/14/12
to mathja...@googlegroups.com
I think your analysis is probably right and that some part of the
Drupal PHP is failing. You might look at the server logs (e.g., the
Apache server logs if you are using Apache) to see if there is
additional information there. It might give you some clues as to what
is going wrong.

Davide

Jason Curley

unread,
Apr 14, 2012, 1:38:59 PM4/14/12
to mathja...@googlegroups.com
Thank you both, Peter and David, for all your help.  I was able to locate the error in the apache log files and I am investigating what happened.  It appears that the error is occurring within the PHP code for the field collection module.  If I learn anything useful about using Drupal, Mathjax and Field Collections or if I have any further questions regarding Mathjax in this issue I will be sure to post them here.

Thanks again to both of you for helping me narrow this down.  The journey of a newbie is a long one indeed!

~Jason

Jason Curley

unread,
Apr 14, 2012, 1:59:16 PM4/14/12
to mathja...@googlegroups.com
In case anyone is curious, the function that breaks with Mathjax enabled is shown below. The error occurs on the line indicated as "Call to undefined function (line 869 of /sites/all/modules/field_collection/field_collection.module)" which works fine when Mathjax is uninstalled or disabled.


/**
 * Implements hook_field_formatter_view().
 */
function field_collection_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];

  switch ($display['type']) {
    case 'field_collection_list':

      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $output = l($field_collection->label(), $field_collection->path());
          $links = array();
          foreach (array('edit', 'delete') as $op) {
            if ($settings[$op] && field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
              $title = entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]);
              $links[] = l($title, $field_collection->path() . '/' . $op, array('query' => drupal_get_destination()));
            }
          }
          if ($links) {
            $output .= ' (' . implode('|', $links) . ')';
          }
          $element[$delta] = array('#markup' => $output);
        }
      }
      field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
      break;

    case 'field_collection_view':

      $element['#attached']['css'][] = drupal_get_path('module', 'field_collection') . '/field_collection.theme.css';
      $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $element[$delta]['entity'] = $field_collection->view($view_mode);
          $element[$delta]['#theme_wrappers'] = array('field_collection_view');
          $element[$delta]['#attributes']['class'][] = 'field-collection-view';
          $element[$delta]['#attributes']['class'][] = 'clearfix';
          $element[$delta]['#attributes']['class'][] = drupal_clean_css_identifier('view-mode-' . $view_mode);

          $links = array(
            '#theme' => 'links__field_collection_view',
          );
          $links['#attributes']['class'][] = 'field-collection-view-links';
          foreach (array('edit', 'delete') as $op) {
            if ($settings[$op] && field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
              $links['#links'][$op] = array(

/*
<------------------------ CALL TO UNDEFINED FUNCTION 'entity_i18n_string' OCCURS ERROR OCCURS on line of code below  ----------------------->
*/

                'title' => entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]),
                'href' => $field_collection->path() . '/' . $op,
                'query' => drupal_get_destination(),
              );
            }
          }
          $element[$delta]['links'] = $links;
        }
      }
      field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
      break;

    case 'field_collection_fields':

      $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $element[$delta]['entity'] = $field_collection->view($view_mode);
        }
      }
      break;
  }

  return $element;

Davide P. Cervone

unread,
Apr 14, 2012, 6:42:31 PM4/14/12
to mathja...@googlegroups.com
Here is some information on this:

http://drupal.org/node/1448594
http://drupal.org/node/1513406
http://drupal.org/node/1471840

It looks like there is a patch that you can apply to fox the problem.
It doesn't seem to be related to MathJax in any way, but perhaps
installing the MathJax extension updated part of your system and
caused the error.

Davide

Jason Curley

unread,
Apr 15, 2012, 11:17:12 AM4/15/12
to mathja...@googlegroups.com
You are a hero and a saint.  I came home from my other job last night prepared to get my hands dirty but was pleasantly surprised to see that it appears I will not have to do so.  I have to go back to work again today, but I will roll this solution out tonight or tomorrow.  I will be sure to post my results.  Many thanks Davide!  Cheers.

~Jason

Jason Curley

unread,
Apr 16, 2012, 5:04:39 PM4/16/12
to mathja...@googlegroups.com
Implementing the changes from the drupal groups worked like Magic.  Thanks!




On Friday, April 13, 2012 3:19:33 PM UTC-4, Jason Curley wrote:

Davide P. Cervone

unread,
Apr 16, 2012, 5:23:17 PM4/16/12
to mathja...@googlegroups.com
Great! Glad that it worked out for you.

Davide

Reply all
Reply to author
Forward
0 new messages