Skip to content

Instantly share code, notes, and snippets.

@Maurisss94
Created August 25, 2019 09:47
Show Gist options
  • Save Maurisss94/3acc709e30aea3831151f0dc3bed2409 to your computer and use it in GitHub Desktop.
Save Maurisss94/3acc709e30aea3831151f0dc3bed2409 to your computer and use it in GitHub Desktop.
Generate a text file with a latex formatted list
<?php
header('Content-type: text/plain; charset=utf-8');
$myfile = fopen("output.txt", "w") or die("Unable to open file!");
$tasks = [
'one task',
'two task'
];
$content = '';
$content .= print_latex_list_format(0, "TITLE");
$content .= print_latex_list_of_list_format("TITLE", "DESCRIPTION", $tasks, "DELIVERABLE", "TIMING");
fwrite($myfile, $content);
function print_latex_list_format($number, $title)
{
$res = "";
$number = sprintf("%02d", $number);
$text_bf = '\textbf';
$res .= "\begin{itemize}\n\item ". $text_bf ."{RF-" . $number . "}: " . $title . "\n" ;
$res .= "\begin{itemize}\n\item ". $text_bf ."{RF-". $number . ".01} Part Backend \n";
$res .= "\item ". $text_bf ."{RF-". $number . ".02} Part Frontend \n";
$res .= '\end{itemize}' . "\n";
$res .= '\end{itemize}' . "\n";
$res .= "\n\n";
return $res;
}
function print_latex_list_of_list_format($title, $desc, $array_tasks, $deliverable, $timing)
{
$res = "";
$text_bf = '\textbf';
$res .= "\begin{itemize}\n\item ". $text_bf ."{".$title."} \n" ;
$res .= "\begin{itemize}\n\item ". $text_bf ."{Descripció: }". $desc. "\n";
$res .= "\item ". $text_bf ."{Tasques: }\n". print_array($array_tasks) . " \n";
$res .= "\item ". $text_bf ."{Lliurables: }". $deliverable . " \n";
$res .= "\item ". $text_bf ."{Temps: }". $timing . " \n";
$res .= '\end{itemize}' . "\n";
$res .= '\end{itemize}' . "\n";
$res .= "\n\n";
return $res;
}
function print_array($arr)
{
$res = "";
$res .= "\begin{itemize}\n";
foreach ($arr as $value) {
$res .= "\item{" . $value . "}\n";
}
$res .= '\end{itemize}';
$res .= "\n";
return $res;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment