在不同文字處理系統(如 MiKTeX, TeX Live, CTeX, cwTex) 或 不同整合開發環境 ( 如Texstudio, WinEdt, TeXstudio, TeXmaker) 中,我用了 Miktex + Texstudio 的常用組合 (win10環境中)。1: 先MiKTeX,后Texstudio ;
2: 安裝包(packages);
3:設置Texstudio的編譯器和默認文獻工具 ;
4:插入 公式, table, 和 figure ;
5: 參考文獻的添加;
6 : 檢查 .bib 中的參考文獻是否重復添加
7: 生成pdf,并保存.tex版本;
8: 用 latexdiff 比較 不同 .tex 版本之間的差異,并自動標注
9: .tex 格式轉換成word格式
10: 截圖的公式,轉換成word格式
1. 先MiKTeX,后Texstudio
Texstudio 是編輯器,通過 mpm (MiKTeX Package Manager) 裝不同的包 。安裝完 Miktex,在終端中輸入 mpm 來查看 MiKtex Console是否存在并打開。
2:安裝包(packages)
在開始菜單 (或終端) 輸入 mpm并回車運行。 在 MiKtex Console,點擊“Switch to administrator mode” (彈出"用戶賬戶控制", 選擇"允許"), 在左側邊欄選擇“Package”, 輸入包名 按加號。
“ Package Manager ” 和 MiKtex Console 的Package編輯界面很像。 但在 “ Package Manager ”添加包會報 " MiKTeX Problem Report:The operation could not be completed because a required file does not exist. "。
3:設置Texstudio的編譯器和默認文獻工具
IOP期刊論文時用是IOP template,編譯器是PdfLatex,文獻工具是:BibTex。當寫畢業論文的時候,學校對字體有規范,用XeLatex編譯器。PdfLatex編譯的速度比較快。
4:.tex template 插入公式, 表格和圖片
期刊一般會提供 Latex template,通過 texstudio打開模板中的".tex", 文本中的數學符號 ($...$)、公式、表格 、圖片把內容替換進去。比如 IOP 定義了如下命令,分別引用section,figure,table 等,自動加上對應的前綴:
\newcommand{\eref}[1]{(\ref{#1})} \newcommand{\sref}[1]{section~\ref{#1}} \newcommand{\fref}[1]{figure~\ref{#1}} \newcommand{\tref}[1]{table~\ref{#1}} \newcommand{\Eref}[1]{Equation (\ref{#1})} \newcommand{\Sref}[1]{Section~\ref{#1}} \newcommand{\Fref}[1]{Figure~\ref{#1}} \newcommand{\Tref}[1]{Table~\ref{#1}}
用 IOPLatexGuidelines模板對格式的要求和示例很詳細,但 iopart (\documentclass[12pt]{iopart}) 與常用的用于公式的宏包
Put the following two lines before just before \usepackage{amsmath} ( 祝曹祥 )
\expandafter\let\csname equation*\endcsname\relax
\expandafter\let\csname endequation*\endcsname\relax
表格, 圖片,公式格式舉例:
\begin{table}
\caption{BCI performances of Group A and Group B}
\lineup
% \footnotesize\rm
\begin{indented}
\item[]\begin{tabular}{@{}llllllll}
\br
& Test & SNR & Accuracy ($\%$) \\ \mr
Group A & test1 & $1.898\pm0.682$ & $78.80 \pm 18.87$ \cr
& test2 & $2.058\pm0.720$ & $84.15 \pm 15.00$ \cr
Group B & test1 & $1.795\pm0.405$ & $74.00 \pm 10.30$ \cr
& tesr2 & $1.530\pm0.391$ & $72.40 \pm 15.80$ \cr
\br
\end{tabular}
\end{indented}
\label{GroupPerfor}
\end{table}
\begin{figure}
\centering
\includegraphics[scale=0.78]{figs/SNRaccuracyGroupAB}
\caption{Comparisons...}
\label{SNRaccuracyGroupAB}
\end{figure}
\begin{equation}
SNR=\frac{n \times X(K)}{\sum_{k=1}^{n/2}[X(K+k)+X(K-k)]}
\end{equation}
* \label{} 要緊挨著 \end{} 之前申明,過早申明就會報錯。
TIPS:
1) 編輯表格生成.tex 表格代碼: online, 適用于畢業論文,需要安裝的package在復制以后會以%提示,沒有提示則不需要另外添加包;從excel復制表格進tablegenerator之前,表格不要留空或者使用合并單元格(可以用_代替)。
2) 將截圖公式轉換成.tex code 公式代碼 : Mathpix snipping tool, 快捷鍵:CTRL+ALT+M** , 生成的代碼,未安裝的包用\usepackage{}添加。
5: 參考文獻的添加
用 BibTeX 工具,生成參考文獻。涉及額外的兩個文件:.bst (生成的references的格式) 和 .bib。期刊提供的 .bst 默認了生成的reference的形態格式。對于 .bib,復制scholar提供的標簽和內容,在.tex正文中用 \cite{} 引用@article{} 括號中的標簽內容。
連續添加多個參考,如 xxx. [8-11]的形式,不是 xxx.[8,9,10,11],需要另外添加 \usepackage{cite} (在導言中), 在正文部分,將文獻標簽以逗號隔開。
6: 檢查 .bib 中的參考文獻重復復制 bibtex并在正文引用,在Bibliography處就會生成兩個相同的reference。查驗 bibtex中的文章是否重復。已經有stackovernet的網友Martin解決了。
該方法是通過 perl在powershell,遍歷.bib 文檔。#!perl
my %seen =();
my $line = 0;
open my $B, 'file.bib';
while () {
$line++;
# remove all non-alphanumeric characters, because bibtex could have " or { to encapsulate strings etc
s/[^a-zA-Z0-9 _-]//ig;
# lower-case everything to be case-insensitive
# pattern matches lines which start with title
$seen{lc($1)} .= "$line," if /^\s*title\s*(.+)$/i;
}
close $B;
# loop through the title and count the number of lines found
foreach my $title (keys %seen) {
# count number of elements seperated by comma
my $num = $seen{$title} =~ tr/,//;
print "title '$title' found $num times, lines: ".$seen{$title},"\n" if $num > 1;
}
# write sorted list into file
open my $S, '>sorted_titles.txt';
print $S join("\n", sort keys %seen);
close $S;
以下是該方法的復述總結: 以上代碼保存程 finddupls.pl 文檔放在.bib所在文件夾。 打開powershell, 執行語句: perl finddupls.pl
有重復會列出title。
2. 添加中文文獻, 在導言加:
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
7: 生成pdf,并保存.tex版本
編譯,生成并保存pdf文件,保存 .tex 文件(建議根據日期或版本命名)。
8: 用 latexdiff 比較 不同 .tex 版本之間的差異,并自動標注
安裝 latexdiff 的包。 將兩個版本的 .tex 與其引用文件放在同一文件夾下。 在powershell 窗口中輸入: latexdiff 舊的版本名.tex 新的版本名.tex > diff.tex
注意:偶爾會出現生成的diff.tex,沒有 .aux 文件對應,此時將 diff.tex的文件內容復制到新建的.tex中并運行,生成pdf。
9: latex的 .tex 格式轉換成word格式
GrindEQ 是MS word的官方插件, 把.tex文件轉換成word。備份.tex文件,用word打開,文件格式選.tex。 轉換出來的bibliography 和公式都沒問題。只是文中 \Fref, \Tref, \cite 的引用效果都不在了, 需要再編輯。
10: 截圖的公式,轉換成word格式
Mathpix snipping tool 可以將截圖里的公式輸出 .tex code, 把code 復制到 .tex。用.tex格式當成一個中轉。 通過安裝 GrindEQ (作者 Daniel D. Zhang)插件,在 word 打開 .tex的文檔,tex的公式都是已word公式顯示。
更新,GrindEQ這個軟件不注冊只能試用。試用期結束以后,價格是100歐元。然后chrome的擴展可以繼續解決 latex to word轉換公式。
將.tex公式(比如從 Mathpix snipping tool copy得到)復制到網址文本框: http://bandicoot.maths.adelaide.edu.au/MathJax/test/sample-dynamic-2.html 右擊 LaTeX2Word-Equation,自動復制,然后在word打開。
作者聲明:
1、轉載或使用請聯系作者。
2、歡迎并感謝指出文中其中可能存在的錯誤或不妥之處。