Tuesday, September 30, 2014

PHP, convert latex to pdf

To convert latex to pdf in PHP, first we need to download text live
xelatex  executable from text live will be used in PHP 
1) In temporary directory, we put the text template as a tex file and run xelatex to convert tex to pdf.
then display pdf file.
ob_get_contentsReturn the contents of the output buffer
 tempnamCreate file with unique file name
sys_get_temp_dirReturns directory path used for temporary files
basenameReturns trailing name component of path

        include 'latex_template.php';
        $outputData .= ob_get_contents();
        $texFile = tempnam(sys_get_temp_dir(), 'test');
        $base = basename($texFile);
        rename($texFile, $texFile.".tex");
        $texFile .= ".tex";
        file_put_contents($texFile, $outputData);

        $console = shell_exec("xelatex {$base}");
        header("Content-type: application/pdf");
        $pdf =    dirname(realpath($texFile)).DIRECTORY_SEPARATOR.$base.".pdf";


\section*{Notes for My Paper}

Don't forget to include examples of topicalization.
They look like this:

\enumsentence{Topicalization from sentential subject:\\
\shortex{7}{a John$_i$ [a & kltukl & [el &
  {\bf l-}oltoir & er & ngii$_i$ & a Mary]]}
{ & {\bf R-}clear & {\sc comp} &
  {\bf IR}.{\sc 3s}-love   & P & him & }
{John, (it's) clear that Mary loves (him).}}

\subsection*{How to handle topicalization}

I'll just assume a tree structure like (\ex{1}).

\enumsentence{Structure of A$'$ Projections:\\ [2ex]
    & \node{i}{CP}\\ [2ex]
    \node{ii}{Spec} &   &\node{iii}{C$'$}\\ [2ex]
        &\node{iv}{C} & & \node{v}{SAgrP}


Mood changes when there is a topic, as well as when
there is WH-movement.  \emph{Irrealis} is the mood when
there is a non-subject topic or WH-phrase in Comp.
\emph{Realis} is the mood when there is a subject topic
or WH-phrase.


  Video: PHP, convert latex to pdf

Monday, September 22, 2014

Add knockout.js in CodeIgniter

CodeIgniter - PHP Model-View-Controller (MVC), can be downloaded from:

knockout.js - JavaScript (MVC) can be downloaded from

Create assests/js folder and copy knockout library  knockout-3.2.0.js to this folder.
Under application/controllers, create test.php
class Test extends CI_Controller {
    public function index() {
        echo '<h2>Add knockout.js in CodeIgniter</h2>';

Under applications/views folder, create test.php
<!DOCTYPE html>
<html lang="en">
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>

<p>Full name: <strong data-bind="text: fullName"></strong></p>

<script type="text/javascript" src="<?php echo base_url('assets/js/knockout-3.2.0.js') ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/inputname.js') ?>"></script>

Under assests/js folder, create inputname.js
// Here's my data model
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
    this.firstName = ko.observable("Jiansen");
    this.lastName = ko.observable("Lu");

    this.fullName = ko.computed(function() {
        return this.firstName() + " " + this.lastName();   
    }, this);
// Activates knockout.js
ko.applyBindings(new AppViewModel());

My case, run: (I create a parent folder MVC0
Video: Add knockout.js in CodeIgniter