使用 LaTeX 方法建立 LyX 文檔。 (LaTeX 編碼並導入 LyX)

使用 LaTeX 方法建立 LyX 文檔。 (LaTeX 編碼並導入 LyX)

具體問題: 我從未使用過LyX,但想知道是否有可能使用LaTeX我最喜歡的編輯器(如emacs或任何文字編輯器),然後將我的程式碼添加到LyX(包括參考書目等),但沒有任何特殊的格式化命令,並且有一個工作 LyX 文件看起來並且可以編輯,就像我使用 LyX 創建它一樣。

更一般: 我應該做什麼以及在使用上述方法建立 LyX 文件時必須小心LaTeX。我的意思是我可以想像這些:

  1. 我可以用簡單的數學和文字複製程式碼,然後按一個鍵並將其作為程式碼匯入到 LyX 環境中,然後等待文件的外觀符合預期。

  2. 對於方程式,我是否需要打開一個新框,並將方程式的內容與其他文字分開添加

  3. 對表格執行與上面相同的操作(使用我可以想像的更簡單的 LaTeX 命令,然後嘗試對其進行格式化)

  4. 將檔案匯入.bibLyX 並以某種方式在步驟 1 中匯入(如果我在文字程式碼中有\cite{key1},或者\citep{key1}我期望 LyX 的正常 LaTeX 行為。)

PS:我可以想像建立一個空文檔LyX作為第一步,只使用程式碼範例來建立一些基本元素,然後匯出到 LaTeX 以了解應該如何執行上述步驟。 (例如,如果我應該使用\(\)or \[\]... 但由於我從未使用過 LyX,我真的不知道獲取典型 LyX 文件的 cdorrect 方法。)

編輯:接下來是一個簡單的文檔,我想測試它是否可以毫無問題地導入 LyX:

\documentclass{article}
\usepackage{multirow}
\usepackage{array}
\usepackage{natbib}
\begin{document}
This is a test file that we will try to import inside `LyX' document and we could or should expect the word ``LyX'' to be inside regular \LaTeX{} single and then double quotation marks. Also contains a variable $x_t$ with $t$ being the superscript.

\begin{table}
\begin{tabular}{|l|m{3cm}|c|p{4cm}|}
\hline
\textbf{No} & \textbf{Empty column}&\textbf{Centered}& \textbf{``Auto-Broken''}\\\hline
1 & &First row& This is a text that will span in two rows of $4\;cm$ maximum width\\\hline
2--3&\multicolumn{2}{c|}{\multirow{2}{*}{columns 3--3 centered}} & Text here not spaned\\\cline{4-4}
&\multicolumn{1}{c}{}&& Text here not spaned\\\hline
4& & Centered $F(x)$& Last spanned cell here with length of $4\;cm$\\\hline
\end{tabular}
\end{table}

According to citation~\cite{citation1} \citeauthor{citation2}, should have write that book~\citep{citation2} 

\bibliographystyle{apalike}
\bibliography{MyBib}

\end{document}

使用參考書目檔案 MyBib.bib:

@article{citation1,
author={Konstantinos Leledakis},
title={Nothing to say about it!},
year={2019},
journal={Never publishing\ldots}
}

@book{citation2,
author={Albert Einstein},
title={Never told this sh$\|$t!},
year={1920},
publisher={Should be published!}
}

輸出應該接近圖片:

在此輸入影像描述

LyX 環境的行為應該與 LyX 本身創建的一樣。例如,您應該能夠編輯表格的元素或更改我在“變數”中錯誤命名為“上標”的下標x_t

PS:新增multirow以防萬一...但如果它產生問題可以刪除。

答案1

這不是完整的答案,因為您有很多不同的問題:-)

因此我可能需要隨著時間的推移添加它

在工作的 TeX 系統上安裝 LyX 時要小心,因為在 Windows 上它會劫持並顯著修改註冊表,而且在其他元件上有許多變體,例如 GhostScript、dvipng、Perl 等
。功能之外,它與簡單編輯器的工作方式。

然而對於一個標準的 tex 來說,使用\parbox:-) 在此輸入影像描述

TeX 導入將立即生成
在此輸入影像描述

它保存在 93 行的純文字檔案中!如果我們忽略前 75 行,就像設定的專用序言一樣,那麼最後幾行是

\end_header

\begin_body

\begin_layout Standard
\begin_inset Formula 
\[
q_{1}^{*}=\frac{\text{number of women who had their second birth in 1971}}{\text{\parbox{4.5cm}{\centering number of women who had their first birth in 1970}}-\text{\parbox{4cm}{\centering number of women had their second birth in 1970}}}
\]

\end_inset


\end_layout

\end_body
\end_document

因此,理論上,對於一個非常基本的獨立條目,添加帶有小型 4 行尾部的預設標題可能很容易

確保更複雜的條目(例如使用 hyperref(有自己的設定))的唯一方法是建議使用者嘗試匯入,然後慢慢解決每個介面錯誤情況。


透過 TeXworks 運行 MWE 只是為了信心檢查我的系統是否正常工作,然後通常使用 pdfLaTeX 的第一次傳遞需要使用 bibtex 設定進行編譯,然後 PDF 如上面的範例所示(無需再次顯示)注意兩個步驟是必需的。

在沒有範本的情況下啟動 LyX 並簡單地匯入 tex 檔案會產生此視圖,我們可能會注意到在處理跨區框時存在細微的潛在差異 在此輸入影像描述

然而,只需單擊“查看”即可獲得確認的 PDF 在此輸入影像描述  
 
只需點擊幾下表格屬性圖示(就像在 word/excel 中一樣)即可輕鬆修正表格輸出

在此輸入影像描述

任何「往返」的證明都是比較輸出,LyX 有多種輸出可供選擇,如下所示。

在此輸入影像描述

選擇 PdfLaTeX 作為比較的合適選擇後,我們得到了這個新的 TeX 檔案。

%% LyX 2.3.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass{article}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage[authoryear]{natbib}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{multirow}
\usepackage{array}

\makeatother

\begin{document}
This is a test file that we will try to import inside `LyX' document
and we could or should expect the word ``LyX'' to be inside regular
\LaTeX{} single and then double quotation marks. Also contains a variable
$x^{t}$ with $t$ being the superscript.

\begin{table}
\begin{tabular}{|l|m{3cm}|c|p{4cm}|}
\hline 
\textbf{No}  & \textbf{Empty column} & \textbf{Centered} & \textbf{``Auto-Broken''}\tabularnewline
\hline 
1  &  & First row & This is a text that will span in two rows of $4\;cm$ maximum width\tabularnewline
\hline 
2--3 & \multicolumn{2}{c|}{\multirow{2}{*}{columns 3--3 centered}} & Text here not spaned\tabularnewline
\cline{1-1} \cline{4-4} 
 & \multicolumn{1}{c}{} &  & Text here not spaned\tabularnewline
\hline 
4 &  & Centered $F(x)$ & Last spanned cell here with length of $4\;cm$\tabularnewline
\hline 
\end{tabular}
\end{table}

According to citation~\citet{citation1} \citeauthor{citation2},
should have write that book~\citep{citation2}

 \bibliographystyle{apalike}
\bibliography{MyBib}

\end{document}

如果沒有測試所有普通乳膠選項,我不知道它是否是最好的,但在 TeXworks 中的修正效果很好,在標準 2 次運行後產生了非常可靠的輸出。據我所知,渲染的表格位置應該與上面修正後的 pdf 幾乎相同。

相關內容