您(个人)如何让 latex 源代码更具可读性?有时,如果 \section{} 或 \proposition{} 没有弹出,则可能很难进行视觉导航。TexStudio 中的语法突出显示还可以,但部分、定理、对齐等看起来都一样:大小、颜色、字体相同。我可能有 5 个嵌套环境,这在视觉上会造成问题。
你只是习惯了扫描,还是有更好的方法?源代码有最佳实践吗?
到目前为止,我一直在使用注释标记来使表达更清晰。但这可能会很乏味。例如
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{proposition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Let $A:\mathcal{H}\rightarrow 2^{\mathcal{H}}$ be a monotone, set-valued operator. $A$ is $\sigma$- strongly maximally monotone if and only if $J_{\gamma A}$ is $1+\gamma\sigma$-cocoercive.
\end{proposition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
答案1
我认为这是非常个人化的,也取决于你排版的文档类型。
至少,您的编辑器应该保留缩进并提供语法突出显示。理想情况下,它应该能够为您正确缩进(或者,至少在绝大多数简单情况下纠正缩进);支持自定义语法突出显示;支持代码折叠(理想情况下可自定义)。
至少,当有现成的宏支持时,您应该使用语义标记将内容与格式分开。理想情况下,您应该创建自定义宏来支持自定义语义标记,从而减少文档混乱。
这是基于您的代码片段并带有一些注释的最小示例。
\documentclass{article}
% BEGIN preamble
% The preamble gets special comment lines which Kile recognises as a bit of code which can be folded or unfolded.
% If the document gets too cluttered, I'm probably not using semantic mark-up and need to add some code here or in a custom class or package to keep format distinct from content.
% END preamble
\begin{document}
Each sentence gets a new line to facilitate versioning.
Every sectional division gets a \verb|\label| followed by a \verb|% BEGIN <label>| and is ended by a \verb|% END <label>|.
Kile will make the result foldable, even though it is not an environment.
\section{A section}\label{sec:section}
% BEGIN sec:section
\begin{proposition}
Let $A:\mathcal{H}\rightarrow 2^{\mathcal{H}}$ be a monotone, set-valued operator.
$A$ is $\sigma$- strongly maximally monotone if and only if $J_{\gamma A}$ is $1+\gamma\sigma$-cocoercive.
\end{proposition}
% END sec:section
\end{document}
答案2
编辑器在提高可读性方面起着至关重要的作用,但明智地使用注释有助于提高文件的可读性。我不认为存在一种最佳方法。显然,cfr 的方法效果很好。我使用以下方法已有一段时间,对我来说效果很好 --- 但我倾向于在终端仿真器(即)中使用 Emacs ,因此这可能意味着它在其他编辑器中不会那么有用。例如,“注释行”全部延伸到第 70 个字符,因为 Emacs 会在该位置emacs -nw
硬换行(例如 via )。M-q
\documentclass[openany]{report}
% Fonts and Encoding ================================================
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
% Language settings --------------------------------------------------
\usepackage[british]{babel}
% Page Layout ========================================================
% Page dimensions ----------------------------------------------------
\usepackage{geometry}
% Headers / Footers --------------------------------------------------
\usepackage[compact, pagestyles]{titlesec}% loads titleps.sty
% commands about section-styline
% commands about headers and footers
% and so on....
\begin{document}
% Front matter =======================================================
\tableofcontents
% Main matter ========================================================
\chapter{Above All, Use Emacs}% ==============================
Emacs offers all the usual bells and whistles that help make writing
.tex documents easier.
\section{\ldots But If You Must}% ------------------------------------
Apparently other editors offer some measure of functionality. Make
sure yours helps you with syntax highlighting, and code indenting at a
bare minimum.
\section{Make Use of Comments}% --------------------------------------
I like to distinguish between comments that use an equal sign (viz,
\verb+===+) and comments that use a simple dash (i.e.,
\verb+---+). The former is indicates---in a very general sense---a
bigger `division' in the document compared to the latter. I find it
less jarring that a solid line of \verb+%%%+.
\end{document}
注意:以上内容并非旨在对要使用哪些软件包等做出任何形式的评论。它更多的是展示“评论行”的层次结构:语言和字体是相互关联的,