2023年2月11日土曜日

chrome extention vimium

chrome をキーボード操作したい、という欲求が定期的に出てくる。いろいろ試して、だいたいなんか予想外の挙動が起きてはずしているのだけど、今度はvimiumというものを試してみる。ちょっと試した感じではGmailではキーイベントを取られてしまって動かないっぽい。 こちら にある。 チートシート を転載しておこう。なんかありすぎて わからないが、とりあえずFでリンクが出るのと、 HL でヒストリ移動、JKでタブ移動だけでも、便利。エスケープでモードから抜ける。
?       show the help dialog for a list of all available keys
h       scroll left
j       scroll down
k       scroll up
l       scroll right
gg      scroll to top of the page
G       scroll to bottom of the page
d       scroll down half a page
u       scroll up half a page
f       open a link in the current tab
F       open a link in a new tab
r       reload
gs      view source
i       enter insert mode -- all commands will be ignored until you hit Esc to exit
yy      copy the current url to the clipboard
yf      copy a link url to the clipboard
gf      cycle forward to the next frame
gF      focus the main/top frame


newpage
o       Open URL, bookmark, or history entry
O       Open URL, bookmark, history entry in a new tab
b       Open bookmark
B       Open bookmark in a new tab


find系
/       enter find mode
          -- type your search query and hit enter to search, or Esc to cancel
n       cycle forward to the next find match
N       cycle backward to the previous find match

history
H       go back in history
L       go forward in history

tab
J, gT   go one tab left
K, gt   go one tab right
g0      go to the first tab. Use ng0 to go to n-th tab
g$      go to the last tab
^       visit the previously-visited tab
t       create tab
yt      duplicate current tab
x       close current tab
X       restore closed tab (i.e. unwind the 'x' command)
T       search through your open tabs
W       move current tab to new window
   pin/unpin current tab

2023年1月28日土曜日

visual studio の単語区切り

visual studio には単語単位のforward backward 等があるが、 日本語の編集中にはあんまりうまく機能しない。 藤井大洋先生が、形態素解析を行うランゲージサーバでいれてなにかされている ようだがそれは後で試すとして、とりあえず、単語区切りに「を」とか「が」とか「、」「。」あたりを入れるとちょっとましになる。ちょっとだけど。 こちら を参考に。

2023年1月15日日曜日

SVGファイルの周りを削除

http://alexlenail.me/NN-SVG/LeNet.html で作った画像はSVGになるのだけど、大きい紙の真ん中に書かれている形になるので、 取り込むと周囲に空白ができて困る。bounding box で crop する方法を調べたら あっさり stack overflow にあった。便利だ。。
inkscape -o cropped.svg -D source.svg

2023年1月7日土曜日

jupyter nbconvert でベクタ図入りのノートブックを変換する

nbconvertはpdfやらsvgやらが入ったノートブックを変換すると、inkscapeを使用するらしく、こんなエラーがでる。
FileNotFoundError: [Errno 2] No such file or directory: 'inkscape'
なので、inkscape をインストールして、下のようにしてpathを通す。inkscapeは、app storeからは インストールできないみたいなので、webページからダウンロードした。
ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape \
      /usr/local/bin/inkscape

nbconvert の日本語対応

こちらの記事に まとまっている。 テンプレートファイル index.tex.j2 というファイルを見つけて
\documentclass[11pt]{article}
となっているところを、
\documentclass[xelatex,ja=standard]{bxjsarticle}
と直せばいいのだけど、このindex.tex.j2がどこにあるのかわからない。 こちらにあるように、
$ jupyter nbconvert --to pdf    filename.ipynb --debug
のようにdebugオプションをつけると、templateを探しに行くパスが表示されるのでそこを見ていけばいい。のだが、めちゃめちゃ数が多くてたいへんだった。

2023年1月5日木曜日

jupyter nbconvert でセルの出力を抑制

jupyter のノートブックからHTMLやPDFを nbconvert で生成することができる。 しかし、多くの場合はすべてのセルを表示したいわけではないので、セル単位で 出力を抑制する必要がある。これにはいくつか方法がある nbconvert には preprocessor という概念がある。 この内の、TagRemovePreprocessorを使うと、特定のタグがついたセルの出力を抑制できる。そもそも「タグ」というのは何なのか知らなかったのだけど、セルごとに任意の属性を付加する事ができる仕掛けで、普通のJupyter notebookでもできるし、vscodeでもつけることができる。ただし結構使いづらい。 これを使うと、
jupyter nbconvert --to html --TagRemovePreprocessor.remove_input_tags='{"hide"}' test.ipynb
のようにして、入力セルだけを抑制できる。ここで hide としているのは任意のタグなので、適当に変更することができる。なんで波括弧が要るのか、よくわからない。 remove_input_tags を remove_cell_tags 、 remove_output_tags にすると、それぞれ入出力両方、出力セルのみの出力を抑制できる。

タグは柔軟で素晴らしいのだけど、タグを付けるのが結構面倒だし、ついているのかエディタ上で目視で確認する事ができない。 RegexRemovePreprocessor というものがあり、これはセルの内容に対して、正規表現で検索を行って、マッチしたら出力を抑制してくれる。

jupyter nbconvert --RegexRemovePreprocessor.patterns="['^# hide']" test.ipynb
素晴らしい、がこれはまるごと抑制してしまうので、入力だけ抑制することはできない。 ソースコードはsite-packages/nbconvert/preprocessors にあるのだけど、 全く対応していない。ほんのちょっといじればできそうなんだけどなあ。。 ということで、やってみたらできたので、 こちらにまとめた。

2022年12月30日金曜日

backquote でIME OFF

MDなどでは、backquoteで等幅フォントを出すので、IMEが切れてくれるとありがたい、ということで設定。私はcmd-spaceでIMEのON/OFFをしているので、それを出している。デフォルトだとctl-spaceだとおもう。
  • .config/karabinar/assets/complex_modifications/xxxx.json に下記を登録
    {
      "title": "for vscode md",
      "rules": [
        {
          "description": "turn off IME with backslash",
          "manipulators": [
            {
              "type": "basic",
              "from": {
                "key_code": "grave_accent_and_tilde"
              },
              "to": [
                {
                  "key_code": "spacebar",
                  "modifiers": [
                    "command"
                  ]
                },
                {
                  "key_code": "grave_accent_and_tilde"
                }
              ],
              "conditions": [
                {
                  "type": "input_source_if",
                  "input_sources": [
                    {
                      "language": "ja"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
    
  • karabinar-element のcomplex modificationで選択してインストール