Saturday, September 07, 2013

Displaying Equations in Blogger & Drupal 7

Remember the quadratic formula?

$ x = \dfrac{-b \pm \sqrt{b^2-4ac}}{2a} $

When I was a child, this fine specimen was one of the most important academic utilities for me (aside from the calculator).  The formula allowed me to bypass hours of mathematical transformations, offering easy plug-and-chug handling for quadratic equations.

But this post isn't about my childhood efforts to maximize my free time.  Rather, this is for all math geeks who wish to incorporate a healthy balance of math and science in their websites.

After several hours of hair-pulling updates, I am finally able to implement MathJax on my blog.  This little technical problem actually kept me from blogging for several years.  Why?  Because I want to discuss STEM-related topics and sometimes words aren't enough.

It really shouldn't have taken me this long to implement MathJax, but between solving cancer and running a national non-profit, things happen.  Of course, if I was even remotely good at coding, this wouldn't have been an issue at all.

In case you aren't familiar with it, MathJax is an open source JavaScript display engine for mathematics that works in all browsers.  It renders embedded $ \LaTeX $ (pronounced la-tech or lay-tech) and Mathematical Markup Language (MathML).

Math in my blog?  Yeah.  Although I'm not a rigorous mathematician, equations are essential to all of my research (and to many effective innovations), so I plan to occasionally explore equations here.  In addition, MathJax is just my initial step towards learning the more comprehensive $ \LaTeX $, a sophisticated and information-rich document markup language used throughout academia.

So, in hopes of saving some time for newbie bloggers, I'll use the remainder of this post to share precisely how I implemented MathJax in this Blog... and for good measure, I'll also show you this in Drupal 7.  

Now, I can't promise that I've done this the 'correct' way, but the following time-dependent one-dimensional Schrödinger equation should be evidence enough:


$ \left [ - \frac{\hbar^2}{2 m} \frac{\partial^2}{\partial x^2} + V \right ] \Psi = i \hbar \frac{\partial}{\partial t} \Psi $









MathJax in Blogger / blogspot.com

Here's how to get MathJax working in your own Blogger site:   Edit the HTML and add the following code immediately below <head>. That's all.  Well, almost.

This Git has been formatted for visibility on this blog.  In order to get the code to work, you'll need to delete the three backslashes on the right, as well as each of those carriage returns; the backslashes are supposed to indicate the code continues on the next line, but Blogger doesn't process them in the HTML.  The MathJax code should then work for you.




MathJax in Drupal 7.x (and 6.x)
Here I describe 2 examples to get MathJax working in Drupal sites, and these methods seem to work equally well in Drupal 6 & 7:

Example 1 - (This didn't really work for me.)
Install this Drupal module to get some MathJax functionality (but you don't really need this).

Example 2 - (This one worked perfectly for me.)
1.    Do the following to call the MathJax cdn file directly:
        - Edit html.tpl.php in your theme folders (it's a template file).
        - Just before <?php print $scripts; ?>, place the following text:


2.   Comment out any non-coding '\$' signs with a preceding backslash '\\$'.
3.   Start placing your own MathJax equations or references anywhere on the page.  
4.   Find additional examples of MathJax coding (linked here).



Troubleshooting MathJax with Blogger & Drupal
While working through all of this, I came across a few bugs that could be useful to discuss.  If you have other solutions for me, I would appreciate hearing them.

Drupal can be complex if you don't understand overrides and hooks.  I'm still learning and don't know much about hooks.  Occasionally, you will update code and nothing happens when it should.  If this happens to you, try to "flush all caches."  It might just reveal your update.

Blogger seems a buggy to me.  Whenever I edit and save from HTML, my page title and description disappear.  However, they reappear if I:  1) modify their values through the "customize" button, and 2) modify their values a second time, through the "settings" button.  I have no idea why this happens, but this is how I fix it.  Every.  Time.

For those of you who like to copy+paste MathJax, like I do, be careful to use 'clean code' or to strip out any text formatting, because a single  <tag> can keep MathJax from recognizing equations.  Read more on this practice at this page (linked here).

Monday, May 10, 2010

Perspective is found in the most ordinary series of events.

I spent this morning, as usual, in a friendly Starbucks between the parking garage and the Yale School of Medicine. Reading "When Things Fall Apart," I was reminded to be generously kind to myself, as I am generally my worst critic... and that in times of restlessness - refraining and practicing mindfulness can be more healing for people than trying harder to be a helpful person.

After meditating on the Chapters, I closed the book and had my coffee refilled. 

As I added cream and Splenda to my coffee, I barely noticed a woman grab a tissue to blow her nose behind me. A second woman next to me, preparing her coffee, was clearly repulsed. She paused and turned around, overtly engrossed in the grossness, and whispered "disgusting." I silently observed the situation - the second woman held a disgusted look, muttered repulsions, and gave the "evil eye" all the way out the door. I doubt the first woman even realized the second woman was grossed out. Altogether, the three of us had very different experiences in a span of 2 minutes and left Starbucks in very different mindsets.

I thought about the situation and it brought a welcomed reminder that everyone is different - and naturally people have different, sometimes relatively extreme, reactions to ordinary situations. Our extreme may be someone else's normality - and likewise vice versa. Among all of this, bystanders will undoubtedly have their own observation and experiences... and we will eventually all go our separate ways having experienced our own version of reality.

Moments later at work, a friend revealed a breakup situation that was all too familiar to me - both of us are in situations with uncanny similarities. The important details are that both of us are reluctantly single and trying to reconcile unexpected separations from long-distance relationships to which we felt wholly dedicated. I suddenly found myself looking into a mirror which somewhat clarified my situation... and reflecting on my last month allows me to be less critical of myself and move on to accept the only option that remains.

Both situations - at Starbucks and at work - remind me that life experiences between people are often likened to train wrecks. 

At some point, it becomes evident that the train wreck will happen -- but everyone is helpless to do anything as it happens. Further, the people in the train wreck will undoubtedly have extremely different perspectives on what happened -- as will the bystanders.

I compared situations, and then I also realized that some train wrecks happen in daylight... and some happen in complete darkness. The difference between the two is that everyone watching a train wreck in darkness may not know what's happening until the daylight hits -- only time can bring the dawn. Until then, invested people will undoubtedly scamper around the wreckage with flashlights to try avoid further disaster... while such actions are justifiable and well-meaning (and may indeed save lives), it is true that people will likely just hurt themselves in the wreckage and only complicate the situation.

Train wrecks in the night might best be left alone until dawn comes, so they can be properly addressed. Sadly, there may be nothing helpful to do but to leave the wreckage to sit during the night -- walk away and nurse your wounds and pray for whatever may happen during the night.

Making it through the night with peace-of-mind might involve Mindfulness, Refraining, and Meditation. Who knows -- in the morning, the apparent train wreck may be nothing more than spilled scrap metal.

Sunday, December 07, 2008

Kindness at its worst...

I've recently learned - no matter how much you wish better for someone... you can't induce positive change in another person's life. For success, there must be a genuine reception, invitation, or acceptance of assistance. Any attempt to provide unwelcome assistance, beyond an offer or a suggestion, will be futile and only make things worse.

Whether the receiver is unable or unwilling to accept help or energy - there are forces keeping the would-be recipient in an unfortunate position. Perhaps the person is precisely where he/she/ze would like.

If you have offered assistance or made suggestions and neither is welcome (or it becomes unwanted should it have already been helpful at one point), then your time is better spent on yourself. If this sounds like you, I encourage you to give your energy to yourself - deconstruct your desire to unabashedly give. A person cannot be assisted if the help is unwelcome. Don't feel guilty or bad if your assistance is rejected.

The inevitable result of attempting to force the situation is a destruction of trust and discomfort for everyone... and the unfortunate likelihood is that everyone involved will be misrepresented and there will be a long, inevitable, painful goodbye.

Friday, December 05, 2008

Resignations, Acceptance of the improbable, or Secretly hoping.

Such a small world we live on, really. 

Our lives criss-cross; perhaps we indulge in a tango; perhaps we find a life-altering friend or purpose... Regardless, our "circles of influence" ebb & flow with Goodbyes & Possibilities. 

With each "Goodbye," we might hold our breath with anticipation. We might find an ebb where we would like some flow. Perhaps we will be pleasantly surprised to find Possibility when we do not expect it.

I think it is this ebb & flow that keep us moving silently forward, living independent lives. We hope - and are either encouraged or discouraged - all the while, holding and cherishing our "Own"... Pressing onwards, slowly acknowledging the ebb & flow will build us up or pick away - at will.

Somewhere along the way, we might find comfort in knowing or resigning, that this is the clockwork of life - although I don't. At some point we might realize we have to accept the world as it is, and that the ebb & flow may not always bring us what we would need or want - although I don't.

I prefer to see and enjoy the ebb & flow in our daily lives in realtime - as it comes & goes... I might enjoy and dance with the waters as they come & go... and I quietly hope there is a larger purpose in which I am performing. And all the while, I do cherish my own, but I also secretly hope "Mine" is really Ours.

Wednesday, December 03, 2008

Broken promises among friends.

Friendships require mutual communication, trust, and forgiveness. Communication is the primary key to relationships. Unlocking this opportunity with shared time and space permits trust to grow.

However, life will always bring unforeseen changes and needs to each person. Without communication, life thus brings distance between friends - expectations and promises can dissolve or distort and become difficult to maintain. In our nomadic, emotionally-repressed society, such situations are inevitable.

When apparent expectations or promises are broken, trust is broken and cannot be mended by one. In fact, trust may never mend. Rebuilding trust requires mutual forgiveness - for lack of communication, for lack of understanding, and for lack of effort.

For those who can rebuild, a new level of trust inevitably brings a stronger bond. Those who cannot rebuild must let go. Only time and patience will distinguish between those who can and cannot rebuild.
~12/03/2008


ADDENDUM:
I've been thinking a lot about this lately and have to acknowledge that how we communicate is very important - and that not everybody does this the same way. While communication is generally necessary for mutual friendships and relationships, forcing a mode of communication can be controlling and destructive -- even if you mean well. When two people don't communicate in the same manner on any particular topic - watch out... forcing your own style can be inflammatory. Sparks can fly and meltdown may be imminent. You may destroy what you are trying to salvage. If both people are intentionally or unintentionally forcing their own communication style - one of the two will eventually need to enter the conversation without any expectations - or both could lose everything.

In anticipation of future meltdowns, it may be useful for any lasting friendship/relationship to delineate how you communicate and the boundaries/expectations around the communication. This may help personal meltdowns to be more productive and allow those around you to respect your communication style(s).