219mze 发表于 2024-8-17 10:18:31

1700页数学笔记火了!全程敲代码,硬核小哥教你上手LaTeX+Vim


    <div style="color: black; text-align: left; margin-bottom: 10px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">晓查 乾明 发自 凹非寺 </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">量子位 <span style="color: black;">报告</span> | 公众号 QbitAI</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">又<span style="color: black;">显现</span>一位“神仙”本科生!</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">数学课上,全程键盘手打1700页笔记。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">速度紧追老师板书,公式、图形一个不落。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果?请看下图:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/01e8570ed3eb4f2b8fc0fcd8ef74ed20~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=ljXnDT7Rs1xGK%2BfZYQVgv8DXmxY%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">不仅排版媲美教科书,<span style="color: black;">况且</span>还能够批注,检索关键词……</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">笔记被他Po到网上之后,便引来<span style="color: black;">海量</span>围观。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">不到一天,<span style="color: black;">关联</span>推文就<span style="color: black;">已然</span>有2000多赞,Hacker News论坛上盖了200多楼。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">乃至</span>有网友评论<span style="color: black;">叫作</span>:“你<span style="color: black;">便是</span><span style="color: black;">咱们</span><span style="color: black;">必须</span>的英雄!”</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">他是怎么做到的呢?<span style="color: black;">奥密</span>武器<span style="color: black;">便是</span>:<strong style="color: blue;">LaTeX</strong>+<strong style="color: blue;">Vim</strong>!</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/515d1642e8a64faa93ae2172dacf9099~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=hR%2FAMBHqs6mOmcuV1tpDRjtI5GE%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这位来自欧洲的小哥非常<span style="color: black;">剧烈</span>安利Vim文本编辑器,他说:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">用LaTeX写数学公式,我选Vim编辑器。它强大、通用、可扩展性很强。只要是基于文本的任务我都用它,写代码、编辑LaTeX、写markdown都是。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然入门<span style="color: black;">周期</span>的学习曲线超级陡峭,但只要<span style="color: black;">把握</span>了基本的操作方式,就会欲罢<span style="color: black;">不可</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面就让<span style="color: black;">咱们</span>看一下他完成这一壮举的<span style="color: black;">详细</span>流程,文中<span style="color: black;">说到</span>的工具下载<span style="color: black;">位置</span>,<span style="color: black;">咱们</span>都附在了最后。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">快速上手教程</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>先<span style="color: black;">瞧瞧</span>小哥的工作环境配置。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">他用Vim编辑LaTeX的场景,就像下面<span style="color: black;">这般</span>:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/ce39f089374e44d6bd18ece55bb5b6c1~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=Qb6kHKp0zSM5tkTbz%2B0tmIAOhHs%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">左边是Vim,右边是pdf阅读器Zathura,它<span style="color: black;">亦</span>有类似Vim的快捷键。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">小哥用的操作系统是Ubuntu,<span style="color: black;">运用</span>bspwm<span style="color: black;">做为</span>窗口管理器。在Vim中,<span style="color: black;">运用</span>的LaTex插件是vimtex,它有语法高亮<span style="color: black;">表示</span>、目录视图、同步对象等功能。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而后</span>,<span style="color: black;">运用</span>vim-plug做如下配置:</p>Plug lervag/vimtex
      let g:tex_flavor=latex
      let g:vimtex_view_method=zathura
      let g:vimtex_quickfix_mode=0
      set conceallevel=1
      let g:tex_conceal=abdmg<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">最后两行<span style="color: black;">掌控</span>的是“<span style="color: black;">隐匿</span>”功能。开启了这个功能,除了你光标所在的那一行之外,文本里夹杂的LaTeX代码就都会<span style="color: black;">隐匿</span><span style="color: black;">或</span>替换成其他符号。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">例如</span>说在下面动图里,<span style="color: black;">隐匿</span>了[,],$之后,<span style="color: black;">无</span>了它们的干扰,<span style="color: black;">全部</span>文档就更易读。这个功能还会用∩替代\bigcap,∈替代\in等等。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/e49347417de44f4591622181ab15e637~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=T%2B4NOZBvSiCfDEbtimkTUglID%2BU%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">设置完成,接下来就到了<span style="color: black;">全部</span>教程的精华所在:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">用LaTeX记笔记,怎么<span style="color: black;">才可</span>像老师写板书<span style="color: black;">同样</span>快?</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这<span style="color: black;">便是</span>片段(snippets)发挥<span style="color: black;">功效</span><span style="color: black;">地区</span>了。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">片段</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">片段是什么?</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">片段是一小段可复用的文本,由其他文本触发。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">例如,输入sign,再按下Tab键,这个单词就会自动扩展为一段签名:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/61aae6c5592b4b1abba82ce50d728971~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=KUA1W9Cqk7uI9NhMLp8IiHooy4Y%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">片段<span style="color: black;">亦</span><span style="color: black;">能够</span>是动态的:输入today并按下Tab键,它就会变成当前的日期。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/38b3fb1021e04169b3c841b8c945fcdb~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=CrkFMncXiigKZXnZWMXQvjbrxLU%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">而输入box按Tab,就会<span style="color: black;">显现</span>一个框,还会随着输入文字自动变大。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/1fa72dc1cf2147cf9a4c5447e1a93c6c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=XOiR4wa%2F0endmOaUhSSBwnzW%2B6E%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">片段,<span style="color: black;">乃至</span><span style="color: black;">能够</span>嵌套在另一个片段里用:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/98e8e7c19d7146ad92fc5f1a289b178c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=nEpv4DeW2n%2FN8fNVM1cr1Rqqeb8%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">怎么创建片段?<span style="color: black;">运用</span>UltiSnips</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">管理片段的插件UltiSnips,小哥是<span style="color: black;">这般</span>配置的:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">关于sign片段的代码如下:</p>snippet sign "Signature"
      Yours sincerely,
      Gilles Castel
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">针对</span>动态的片段,你<span style="color: black;">能够</span>将代码放在``之间, 在片段扩展的时候,就会运行。下面的例子,<span style="color: black;">便是</span>用 bash 格式化当前日期:date+%f。</p>snippet today "Date"
      `date +%F`
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">你<span style="color: black;">亦</span><span style="color: black;">能够</span>在!p ...代码块里<span style="color: black;">运用</span>Python,<span style="color: black;">例如</span>上面box片段的代码<span style="color: black;">便是</span><span style="color: black;">这般</span>的:</p>snippet box "Box"
      `!p snip.rv = ┌ + ─ * (len(t) + 2) + ┐`
      │ $1 │
      `!p snip.rv = └ + ─ * (len(t) + 2) + ┘`
      $0
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些 Python 代码块将被变量 snip.rv 的值替换。在这些代码块中,你<span style="color: black;">能够</span><span style="color: black;">拜访</span>代码段的当前状态,例如t<span style="color: black;">包括</span><span style="color: black;">第1</span>个制表位,fn是当前文件名等等。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">LaTex片段</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span>片段编写LaTeX,要比纯手工编写快得多。<span style="color: black;">尤其</span>有些非常<span style="color: black;">繁杂</span>的片段能帮你大大节约时间,有效防止抓狂。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面是<span style="color: black;">有些</span>非常有用且容易上手的片段:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">环境</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">想<span style="color: black;">插进</span>一个环境,只<span style="color: black;">必须</span>在一行的开头输入beg。<span style="color: black;">而后</span>键入环境的名<span style="color: black;">叫作</span>,这个名<span style="color: black;">叫作</span>在\end{}命令中<span style="color: black;">亦</span>是<span style="color: black;">同样</span>。按下Tab键,就能够将光标<span style="color: black;">安置</span>在新创建的环境中。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/pgc-image/82ba6b5dd8b141fdba57487a5b863cce~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=ie0kxqMm4wNwssIl8nof%2FMYeo70%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个片段的代码如下:</p>snippet beg "begin{} / end{}" bA
      \begin{$1}
      $0
      \end{$1}
      endsnippet
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">其中,b<span style="color: black;">暗示</span>这个片段只会在代码行的开头展开,A<span style="color: black;">表率</span>自动展开,<span style="color: black;">亦</span><span style="color: black;">便是</span>说<span style="color: black;">不消</span>按Tab键了。制表位(Tab stop)——<span style="color: black;">亦</span><span style="color: black;">便是</span>你<span style="color: black;">能够</span><span style="color: black;">经过</span>按Tab 和Shift+Tab<span style="color: black;">转</span>到的位置——用$1、 $2、......来<span style="color: black;">暗示</span>,最后一个用$0。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">行内和数学<span style="color: black;">表示</span></strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在记数学笔记的过程中,最常用的两个片段是mk和dm。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">它们负责<span style="color: black;">起步</span>数学模式。<span style="color: black;">第1</span>个片段用于“行内数学”,第二个用于“<span style="color: black;">表示</span>数学”。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/e977b63a77cf433f98e465fdbe324788~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=JhwIHXWXqmP1saJ22dX1gapT6FE%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码行内的数学片段是“智能的”:它<span style="color: black;">晓得</span>什么时候在$符号后面直接输入一个单词,它会自动加个空格。但<span style="color: black;">倘若</span>输入一个非单词的字符,它就不会添加空格了,<span style="color: black;">例如</span>在““$p$-value”<span style="color: black;">状况</span>下,是<span style="color: black;">这般</span>的:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/pgc-image/e2ecda9aab794087824b9dd9b902e16a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=pP%2BtGuj5M7Dr6dfqrMBSY8Ua6bA%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个片段的代码如下:</p>snippet mk "Math" wA
      $${1}$`!p
      if t and t not in [,, ., ?, -, ]:
      snip.rv =
      else:
      snip.rv =
      `$2
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>行末尾的w,<span style="color: black;">寓意</span>着这个片段会在单词边界处扩展,例如,hellomk不会扩展,<span style="color: black;">然则</span>hello mk会。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">用于<span style="color: black;">表示</span>数学的片段更简单,<span style="color: black;">亦</span>更加方便;有了它,你可能再<span style="color: black;">亦</span>不会忘记用句号结束方程了。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/3a12805a4b2c4bd59c68d6d2e8ae7816~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=JYUtSL%2F%2BFhYwGjWrHWlapAAKxUs%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码:</p>snippet dm "Math" wA
      \[
      $1
      .\] $0
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">小写和上标</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">另一个<span style="color: black;">特别有</span>用的片段<span style="color: black;">便是</span>下标。能够把a1改为a1,把a_12改为a{12}。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/00e16878c3594d4b9f48a841fc7e2e2e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=i5NsLNwllydcK%2B%2Fx3zA7CIRNXxM%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个片段的触发器是<span style="color: black;">运用</span>正则表达式。有两种<span style="color: black;">状况</span>会扩展片段。一是你键入一个字符,后面跟着一个数字,<span style="color: black;">例如</span>\d;另一种是,一个字符后面有并跟着两个数字,<span style="color: black;">例如</span>\d\d。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当你<span style="color: black;">运用</span>括号将正则表达式的一部分装在一个组中时,例如(\d\d),你<span style="color: black;">能够</span>在 Python中<span style="color: black;">经过</span>match.group (i)来<span style="color: black;">运用</span>它们扩展片段。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">至于上标,<span style="color: black;">能够</span><span style="color: black;">运用</span>td,它就会变成^{}。然而,<span style="color: black;">针对</span>平方、立方和其他<span style="color: black;">有些</span><span style="color: black;">平常</span>的片段,<span style="color: black;">能够</span><span style="color: black;">运用</span>专门的代码片段,如 sr、cb等等。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果图:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/f23b2c43f0f64fa693c38ab9572e0ba4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=33KBv6PpSwHFS0JzPAci5O2xloY%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码:</p>snippet sr "^2" iA
      ^2
      endsnippet
      snippet cb "^3" iA
      ^3
      endsnippet
      snippet compl "complement" iA
      ^{c}
      endsnippet
      snippet td "superscript" iA
      ^{$1}$0
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">分数</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">分数是一个用起来最方便的一个片段,扩展的形式如下:</p>/ / → frac {}{}
      3 / → frac {3}{}
      4 pi ^ 2 / → frac {4 pi ^ 2}{}
      (1 + 2 + 3) / → frac {1 + 2 + 3}{}
      (1 + (2 + 3) /)→(1 + frac {2 + 3}{})
      (1 + (2 + 3)) / → frac {1 + (2 + 3)}{<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/4dd1dbe0b57e488ea7f02033fdc85992~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=1Z38yaVqwKrtasXK6KY1qzIhGqs%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>个片段的代码很简单:</p>snippet // "Fraction" iA
      \\frac{$1}{$2}$0
      endsnippet
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">第二个和第三个示例,<span style="color: black;">能够</span><span style="color: black;">运用</span>正则表达式来匹配3/、4ac/、6pi^2/、a2/等表达式。</p>snippet ((\d+)|(\d*)(\\)?(+)((\^|_)(\{\d+\}|\d))*)/ "Fraction" wrA
      \\frac{`!p snip.rv = match.group(1)`}{$1}$0
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">看了上边这些,你可能觉得正则表达式太难了。<span style="color: black;">不碍事</span>,下面有一个解释得非常直观的图表:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/4e436cf11fbc4d58aa96f70d6cb8f2ca~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=IS7Q7rLbZ5%2Fnt4q5XV9AH%2BBEFVA%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在第四和第五种示例下,要换一种<span style="color: black;">办法</span>。<span style="color: black;">运用</span>UltiSnips的正则表达式引擎<span style="color: black;">处理</span>不了的,Python<span style="color: black;">能够</span>:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这儿</span>最后要分享的关于分数的片段,能<span style="color: black;">按照</span>你的<span style="color: black;">选取</span>,来生成一个分数。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">你<span style="color: black;">能够</span>先<span style="color: black;">选取</span><span style="color: black;">有些</span>文本,<span style="color: black;">而后</span>按Tab键,继续输入、<span style="color: black;">而后</span>再按Tab键。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/dfc8b8a7f61e4006b706e149fd380e92~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=LG1nFwBotE3iujULqNhN9MtucAA%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码中,<span style="color: black;">运用</span>${VISUAL}变量来<span style="color: black;">暗示</span>所选的内容。</p>snippet / "Fraction" iA
      \\frac{${VISUAL}}{$1}$0
      endsnippet
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">Sympy和Mathematica</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">还有一个很酷但用得不多的片段,是<span style="color: black;">运用</span>Sympy来计算数学表达式。例如,输入sympy,<span style="color: black;">而后</span>按下Tab,<span style="color: black;">能够</span>扩展为sympy | sympy,输入sympy 1 + 1 sympy,按下Tab,<span style="color: black;">能够</span>扩展为2。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/fa3e2614cbaa462b9c4bc6ffc8c143a3~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=z260YDuWkXUdTN8Aynf3CluJIP4%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">片段代码:</p>nippet sympy "sympy block " w
      sympy $1 sympy$0
      endsnippet
      priority 10000
      snippet sympy(.*)sympy "evaluate sympy" wr
      `!p
      from sympy import *
      x, y, z, t = symbols(x y z t)
      k, m, n = symbols(k m n, integer=True)
      f, g, h = symbols(f g h, cls=Function)
      init_printing()
      snip.rv = eval(latex( + match.group(1).replace(\\, ) \
      .replace(^, **) \
      .replace({, () \
      .replace(}, )) + ))
      `
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">用Mathematica,<span style="color: black;">亦</span><span style="color: black;">能够</span>做类似的事情:</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8e7226a805ce4a229087e4b0641a29a3~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=if9A6kjOamOFow5N8NbAEJ%2B0xps%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">片段代码:</p>priority 1000
      snippet math "mathematica block" w
      math $1 math$0
      endsnippet
      priority 10000
      snippet math(.*)math "evaluate mathematica" wr
      `!p
      import subprocess
      code = ToString[ + match.group(1) + , TeXForm]
      snip.rv = subprocess.check_output()
      `
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">后缀片段</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除了上边这些之外,后缀片段<span style="color: black;">亦</span>很值得分享。例如phat→hat{p}和zbar→overline{z}。还有类似的后缀向量,例如v,.→vec{v}和v.,→vec{v}。.和,的<span style="color: black;">次序</span><span style="color: black;">不碍事</span>,<span style="color: black;">因此</span><span style="color: black;">能够</span><span style="color: black;">同期</span>按下它们两个。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/736d1fa4529d4a5683907f17a47aca28~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=89k7ATGZPG590clBGJihTQQdJ1s%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些片段真的<span style="color: black;">能够</span>节省时间,<span style="color: black;">能够</span><span style="color: black;">根据</span>和老师写板书<span style="color: black;">同样</span>的<span style="color: black;">次序</span>来记。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>,bar和hat前缀<span style="color: black;">亦</span>依然<span style="color: black;">能够</span>用,只要以较低的优先级添加它们就行。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些片段的代码是:</p>priority 10
      snippet "bar" "bar" riA
      \overline{$1}$0
      endsnippet
      priority 100
      snippet "()bar" "bar" riA
      \overline{`!p snip.rv=match.group(1)`}
      endsnippet
      priority 10
      snippet "hat" "hat" riA
      \hat{$1}$0
      endsnippet
      priority 100
      snippet "()hat" "hat" riA
      \hat{`!p snip.rv=match.group(1)`}
      endsnippet
      snippet "(\\?\w+)(,\.|\.,)" "Vector postfix" riA
      \vec{`!p snip.rv=match.group(1)`}
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">其他片段</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">另外</span>,小哥还有大约100个常用的片段(下载<span style="color: black;">位置</span><span style="color: black;">附着</span>文末),大<span style="color: black;">都数</span>都很简单。<span style="color: black;">例如</span>,输入!&gt;变成\mapsto,输入-&gt;变成\to等等。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/971bfed6d0f3408b865c42e38e889765~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=GP9R13zxzr4k1w9%2Fkea3gI85lqg%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">fun变成f: \R \to \R :,!&gt;变成\mapsto,-&gt;变成\to,cc变成\subset。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/74a14cffdac04fceb5276f2515242f98~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=jIVHff55ktXnms%2B6O%2F06%2Fm%2Fu%2FNY%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">lim变成\lim{n \to \infty},sum变成\sum{n = 1}^{\infty},ooo变成\infty。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8dd9cc5ae96f4bbbbec89835761289b9~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=4oGxZo2xQWFQ630aDFmZ0Lc7kYU%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/2cbef0acf3e34c57a4b0bacac962c876~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=88%2B6MmOXGWpCJTo6qrEkKhhFWHA%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">特定课程的片段</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除了<span style="color: black;">有些</span>常用的片段,<span style="color: black;">亦</span><span style="color: black;">能够</span>针对特定的课程设定片段。例如,在量子力学这门课中,<span style="color: black;">能够</span>设定<span style="color: black;">有些</span>关于bra/ket符号的片段。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&lt;a|→\bra{a} &lt;ψ|→\bra{\psi}="" a=""&gt;→\ket{a}</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">|ψ&gt;→\ket{\psi}</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">→\braket{a}{b}</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8bfa5695db3f480583b6d204bcd23cad~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=fmViXo6IwCNUQHwVboLf1TsWyd0%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码:</p>snippet "\&lt;(.*?)\|" "bra" riA
      \bra{`!p snip.rv = match.group(1).replace(q, f\psi).replace(f, f\phi)`}
      endsnippet
      snippet "\|(.*?)\&gt;" "ket" riA
      \ket{`!p snip.rv = match.group(1).replace(q, f\psi).replace(f, f\phi)`}
      endsnippet
      snippet "(.*)\\bra{(.*?)}([^\|]*?)\&gt;" "braket" riA
      `!p snip.rv = match.group(1)`\braket{`!p snip.rv = match.group(2)`}{`!p snip.rv = match.group(3).replace(q, f\psi).replace(f, f\phi)`}
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">上下文</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在编写这些片段时<span style="color: black;">必须</span><span style="color: black;">思虑</span>的一件事是,“这些片段会与长与常用的文本冲突吗?”</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">例如,在英语中大<span style="color: black;">大概</span>72个单词<span style="color: black;">包括</span>sr,这<span style="color: black;">寓意</span>着当输入disregard这个词时,sr会扩展到^2,<span style="color: black;">显现</span>一个di^2egard。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个问题的<span style="color: black;">处理</span><span style="color: black;">方法</span>是,为代码片段添加上下文。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">经过</span><span style="color: black;">运用</span> Vim 的语法<span style="color: black;">明显</span><span style="color: black;">表示</span>,<span style="color: black;">能够</span>确定UltiSnips<span style="color: black;">是不是</span>应该扩展片段,这取决于你<span style="color: black;">运用</span>的是数学还是文本。</p>global !p
      texMathZones = [texMathZone+x for x in [A, AS, B, BS, C,
      CS, D, DS, E, ES, F, FS, G, GS, H, HS, I, IS,
      J, JS, K, KS, L, LS, DS, V, W, X, Y, Z]]
      texIgnoreMathZones =
      texMathZoneIds = vim.eval(map(+str(texMathZones)+", hlID(v:val))")
      texIgnoreMathZoneIds = vim.eval(map(+str(texIgnoreMathZones)+", hlID(v:val))")
      ignore = texIgnoreMathZoneIds
      def math():
      synstackids = vim.eval("synstack(line(.), col(.) - (col(.)&gt;=2 ? 1 : 0))")
      try:
      first = next(
      i for i in reversed(synstackids)
      if i in texIgnoreMathZoneIds or i in texMathZoneIds
      )
      return first != ignore
      except StopIteration:
      return False
      endglobal<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">此刻</span>,你<span style="color: black;">能够</span>将context “math()”添加到只<span style="color: black;">期盼</span>在数学上下文中展开的片段中。</p>context "math()"
      snippet sr "^2" iA
      ^2
      endsnippet<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">请<span style="color: black;">重视</span>,“数学上下文”是一个微妙的东西。 有时你<span style="color: black;">能够</span><span style="color: black;">运用</span>\text{…}在数学环境中添加<span style="color: black;">有些</span>文本。在这种<span style="color: black;">状况</span>下,你不<span style="color: black;">必须</span>扩展片段。<span style="color: black;">然则</span>,在以下<span style="color: black;">状况</span>下: \[ \text{$...$} \],它们<span style="color: black;">能够</span>扩展。 这<span style="color: black;">便是</span><span style="color: black;">为何</span>math上下文的代码有点<span style="color: black;">繁杂</span>。下面的动图说明了这些微妙之处。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/e34b96f954ac4a31860be1b40bebc6e4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=x7kcTHaqVgJtOmqj%2FrA1ZaIFq2E%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">除了<span style="color: black;">以上</span><span style="color: black;">有些</span>片段,你<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">按照</span>自己的<span style="color: black;">必须</span>,来自己添加<span style="color: black;">有些</span>插件<span style="color: black;">或</span>片段,来<span style="color: black;">加强</span>自己的效率。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">用笔还是用电脑?</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">纯手打记下1700页数学笔记,awesome都<span style="color: black;">不足</span>形容了这位小哥了,堪<span style="color: black;">叫作</span>理工科学生中的“英雄”。</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/pgc-image/844fb9ca728e423090bc3d0821c2aa85~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=Dcvyp19tEAmZGFnjIpIoH28u3kc%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">并非所有人都赞同小哥的做法,强大的高科技工具在传统面前常常会被质疑。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">有部分网友认为手写比电脑打字印象深刻,<span style="color: black;">况且</span>要达到这位小哥的<span style="color: black;">熟悉</span>程度,恐怕LaTeX和Vim得练习好几年。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">既然用笔更方便,<span style="color: black;">为何</span>还要用电脑来记笔记呢?<span style="color: black;">原由</span>很简单:字太丑!</p>
      <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/3288009cb9a14bcc8197b1d8a46ea635~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889726&amp;x-signature=RGKgpTNb36RySwtPnnPg6%2FprciA%3D" style="width: 50%; margin-bottom: 20px;"></div>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>记下来的内容连自己看的欲望都<span style="color: black;">无</span>,怎么复习课堂笔记呢?<span style="color: black;">最少</span>用电脑记下来的排版工整,让人赏心悦目。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虽然国外网友争论不休,但在国内只要一个<span style="color: black;">要求</span>就<span style="color: black;">能够</span>彻底否决这个方法:不让带电脑进课堂。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">对此,你怎么看?</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">工具传送门:</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Linux和Mac系统自带Vim。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Windows用户安装Vim:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://ftp.nluug.nl/pub/vim/pc/gvim81.exe</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Vim插件管理:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://github.com/junegunn/vim-plug</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Vim上的LaTeX插件:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://github.com/lervag/vimtex</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">窗口平铺管理器:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://github.com/baskerville/bspwm</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">管理Vim片段工具:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://github.com/SirVer/ultisnips</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>你用不惯Vim,还有Emacs、Atom、VS Code、Sublime,它们都有LaTeX插件,总有一款文本编辑器适合你。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">LaTeX<span style="color: black;">平常</span>数学符号输入<span style="color: black;">办法</span>:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://en.wikibooks.org/wiki/LaTeX/Mathematics</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">想要<span style="color: black;">熟练</span><span style="color: black;">更加多</span>的LaTeX<span style="color: black;">运用</span><span style="color: black;">办法</span>,就<span style="color: black;">必须</span>系统地学习,平时多加练习<span style="color: black;">亦</span>必不可少。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">博文链接:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://castel.dev/post/lecture-notes-1/</p>
    </div>




星☆雨 发表于 2024-8-25 15:02:54

你的言辞如同繁星闪烁,点亮了我心中的夜空。
页: [1]
查看完整版本: 1700页数学笔记火了!全程敲代码,硬核小哥教你上手LaTeX+Vim