figer latex update
This commit is contained in:
@@ -2057,13 +2057,18 @@ class Production extends Base
|
||||
$article_main_info['content'] = $updatedContent;
|
||||
$fragContentList[] = $article_main_info;
|
||||
}elseif ($article_main_info['type']==1){//处理图片
|
||||
|
||||
$fragContentList[] = $this->figerConvertLatex($article_main_info['ami_id']);
|
||||
}else{//处理表格
|
||||
$fragContentList[] = $this->tableCovertLatex($article_main_info['amt_id'],$references);
|
||||
}
|
||||
}
|
||||
//实际生成tex
|
||||
|
||||
$tex_file = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $data['article_id'] . DS . 'article_' . $data['article_id'] . '.tex';
|
||||
$tex_content_last = "";
|
||||
foreach ($fragContentList as $val){
|
||||
$tex_content_last .= $val."/n";
|
||||
}
|
||||
file_put_contents($tex_file, $tex_content_last);
|
||||
|
||||
|
||||
//生成bib文件
|
||||
@@ -2071,19 +2076,149 @@ class Production extends Base
|
||||
$bibContent = $this->generateBibContent($article_production_info['p_article_id'],$references);
|
||||
file_put_contents($file, $bibContent);
|
||||
|
||||
//生成pdf文件
|
||||
$pdfFile = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $data['article_id'] . DS . 'article_' . $data['article_id'] . '.pdf';
|
||||
$command = "cd {$outputPath} && pdflatex -interaction=nonstopmode article_" . $data['article_id'] . ".tex";
|
||||
exec($command, $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
return jsonError("Failed to generate PDF");
|
||||
}
|
||||
// //生成pdf文件
|
||||
// $pdfFile = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $data['article_id'] . DS . 'article_' . $data['article_id'] . '.pdf';
|
||||
// $command = "cd {$outputPath} && pdflatex -interaction=nonstopmode article_" . $data['article_id'] . ".tex";
|
||||
// exec($command, $output, $returnCode);
|
||||
// if ($returnCode !== 0) {
|
||||
// return jsonError("Failed to generate PDF");
|
||||
// }
|
||||
//存储pdf文件
|
||||
|
||||
return jsonSuccess(['file'=>$pdfFile]);
|
||||
return jsonSuccess(['file'=>$tex_file]);
|
||||
}
|
||||
|
||||
|
||||
// public function figerConvertLatex($ami_id){
|
||||
// $ami_info = $this->article_main_image_obj->where("ami_id",$ami_id)->find();
|
||||
// explode("/",$ami_info['url']);
|
||||
// //拷贝图片到目标目录
|
||||
// $filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'articleImage' . DS . $ami_info['url'] ;
|
||||
// $nowFile = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_'.$ami_info['article_id'] . DS . $ami_info['article_id'] . DS . $ami_info['file_name'];
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public function myFigerTest(){
|
||||
echo $this->figerConvertLatex(4172);
|
||||
}
|
||||
|
||||
|
||||
public function figerConvertLatex($ami_id){
|
||||
$ami_info = $this->article_main_image_obj->where("ami_id",$ami_id)->find();
|
||||
$urlParts = explode("/",$ami_info['url']);
|
||||
|
||||
$fileName = $urlParts[count($urlParts) - 1];
|
||||
// 创建目标目录
|
||||
$targetDir = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $ami_info['article_id'];
|
||||
if (!file_exists($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
// 拷贝图片到目标目录
|
||||
$filePath = ROOT_PATH . 'public' . DS . 'articleImage' . DS . $ami_info['url'];
|
||||
$targetFilePath = $targetDir . DS . $fileName;
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
copy($filePath, $targetFilePath);
|
||||
}
|
||||
|
||||
// 检测图片尺寸
|
||||
$imageInfo = getimagesize($targetFilePath);
|
||||
$imageWidth = $imageInfo[0]; // 图片宽度
|
||||
$imageHeight = $imageInfo[1]; // 图片高度
|
||||
|
||||
// 定义宽度阈值(例如:宽度大于600像素则使用两栏)
|
||||
$wideImageThreshold = 600;
|
||||
$isWideImage = $imageWidth > $wideImageThreshold;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 生成LaTeX图片代码
|
||||
if ($isWideImage) {
|
||||
$latexLines[] = "\\begin{figure*}[htbp]"; // 使用figure*环境实现两栏
|
||||
$latexLines[] = " \\centering";
|
||||
$latexLines[] = " \\includegraphics[width=0.9\\textwidth]{" . $fileName . "}"; // 使用全宽度
|
||||
} else {
|
||||
$latexLines[] = "\\begin{figure}[H]";
|
||||
$latexLines[] = " \\centering";
|
||||
$latexLines[] = " \\includegraphics[width=0.9\\textwidth]{" . $fileName . "}";
|
||||
}
|
||||
|
||||
if(!empty($ami_info['title'])&&!empty($ami_info['note'])){
|
||||
$escapedTitle = '{\fontspec{Calibri}\footnotesize\bfseries\color{figerTitleColor} '.$this->convertToLatex(preg_replace('/^Figure\s+\d+\s*/i', '', $ami_info['title']),[]).'}\\\\';
|
||||
$escapedTitle .= '{\vspace{0.5em}\raggedright\small {'.$this->convertToLatex($ami_info['note'],[]).'}}';
|
||||
$latexLines[] = " \\caption{" . $escapedTitle . "}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if (!empty($ami_info['title'])) {
|
||||
// $escapedTitle = $this->escapeLatexSpecialChars(strip_tags($ami_info['title']));
|
||||
// $latexLines[] = " \\caption{" . $escapedTitle . "}";
|
||||
// }
|
||||
//
|
||||
// if (!empty($ami_info['note'])) {
|
||||
// $escapedNote = $this->escapeLatexSpecialChars(strip_tags($ami_info['note']));
|
||||
// $latexLines[] = " \\label{fig:" . $ami_info['ami_id'] . "}";
|
||||
// $latexLines[] = " \\footnotesize{" . $escapedNote . "}";
|
||||
// }
|
||||
|
||||
$latexLines[] = "\\end{figure" . ($isWideImage ? "*" : "") . "}";
|
||||
|
||||
return implode("\n", $latexLines);
|
||||
}
|
||||
|
||||
public function figerConvertLatex11($ami_id){
|
||||
$ami_info = $this->article_main_image_obj->where("ami_id",$ami_id)->find();
|
||||
$urlParts = explode("/",$ami_info['url']);
|
||||
|
||||
$fileName = $urlParts[count($urlParts) - 1];
|
||||
// 创建目标目录
|
||||
$targetDir = ROOT_PATH . 'public' . DS . 'latex' . DS . 'tex_' . $ami_info['article_id'] ;
|
||||
if (!file_exists($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
// 拷贝图片到目标目录
|
||||
$filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'articleImage' . DS . $ami_info['url'];
|
||||
$targetFilePath = $targetDir . DS . $fileName;
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
copy($filePath, $targetFilePath);
|
||||
}
|
||||
|
||||
// 生成LaTeX图片代码
|
||||
$latexCode[] = "\\begin{figure}[H]";
|
||||
$latexCode[] = " \\centering";
|
||||
$latexCode[]= " \\includegraphics[width=0.8\\textwidth]{" . $fileName . "}";
|
||||
|
||||
if (!empty($ami_info['title'])) {
|
||||
$escapedTitle = $this->escapeLatexSpecialChars($ami_info['title']);
|
||||
$latexCode[] = " \\caption{" . $escapedTitle . "}";
|
||||
}
|
||||
|
||||
if (!empty($ami_info['note'])) {
|
||||
$escapedNote = $this->escapeLatexSpecialChars($ami_info['note']);
|
||||
$latexCode[] = " \\label{fig:" . $ami_info['ami_id'] . "}";
|
||||
$latexCode[] = " \\footnotesize{" . $escapedNote . "}";
|
||||
}
|
||||
|
||||
$latexCode[] = "\\end{figure}";
|
||||
|
||||
return implode("\n", $latexCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function convertToLatex($content,$references) {
|
||||
// 空内容直接返回
|
||||
|
||||
Reference in New Issue
Block a user