hohei’s diary

備忘録?

emacsでn文字カーソル移動

移動に便利な avy や ace-jump-mode があるのは知っているのですが,いかんせんブラインドタッチが苦手なのでストレスになります.

なので,単純にn文字カーソル移動 + M-f,M-b するのが自分にはしっくりきてます.同じような人もいるかと思い,教えてもらったコードを公開します ω

;; n文字移動
(defun my-forward-char-n (n)
    (when (eolp)
      (forward-char 1)
      (setq n (1- n)))
    (while (and (not (eolp)) (not (zerop n)))
      (forward-char 1)
      (setq n (1- n))))
(defun my-backward-char-n (n)
    (when (bolp)
      (backward-char 1)
      (setq n (1- n)))
    (while (and (not (bolp)) (not (zerop n)))
      (backward-char 1)
      (setq n (1- n))))

;; キーバインドの設定例
(bind-key "C-j" (lambda () (interactive) (my-forward-char-n 10)))
(bind-key "M-j" (lambda () (interactive) (my-backward-char-n 10)))

とりあえずプリアンブルに加えておくべき余白設定

とりあえず以下をプリアンブルに加えよう.自分好みに調節してください ω

% 数式(演算子など)のスペースを詰める
% =,→ 間の余白
\thickmuskip=1.0\thickmuskip
% +,- 間の余白
\medmuskip=0.8\medmuskip
% … などの装飾記号の余白
\thinmuskip=0.8\thinmuskip
% 行列を詰める
\arraycolsep=0.3\arraycolsep
% 数式の上下のスペースの変更
\AtBeginDocument{
  \abovedisplayskip     =0.5\abovedisplayskip
  \abovedisplayshortskip=0.5\abovedisplayshortskip
  \belowdisplayskip     =0.5\belowdisplayskip
  \belowdisplayshortskip=0.5\belowdisplayshortskip}

数式の上下のスペースの変更で以下のように設定しているものをよく見かけますが,せっかくのグルーが消えちゃうからよくない?

\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}

加えたもの.行列はわかりやすいですね.

加えなかったもの

ソースファイルです.文脈は無視してください ω

\documentclass[11pt,a4j,papersize,uplatex,fleqn,dvipdfmx]{jsarticle}
\usepackage{amsmath,amssymb,amsthm,enumerate}

\begin{document}
\begin{align}
  a&=160+x, & b&=160+y & & \label{16_3}
\end{align}
とおく.データの平均値が160なので
\begin{align*}
  160&=\frac{1}{7}\left( a+b+152+158+160+162+163 \right)\\
     &=\frac{1}{7}\left\{ (160+x)+(160+y)+(160-8)+(160-2)+160+(160+2)+(160+3) \right\}
\end{align*}
両辺に7をかけて
\begin{align}
  160\cdot 7&=160\cdot 7+\left( x+y-8-2+2+3 \right) & \therefore\quad
  x+y&=5 & & & \label{16_1}
\end{align}
が分かる.また,データの標準偏差が$\sqrt{14}$なので
\begin{align}
  14\cdot 7=x^2+y^2+81 \quad\quad \therefore\quad
  x^2+y^2=17 \label{16_2}
\end{align}
が分かる.% \eqref{16_1}より$y=5-x$を\eqref{16_2}に代入して$y$を消去すると
直線$y=2x$の傾きは2,直線$2x+3y=6$の傾きは$-\dfrac{2}{3}$なので
\begin{align*}
\tan{\alpha}&=2, & \tan{\beta}&=-\frac{2}{3} & & &
\end{align*}
とおく.このとき
\begin{align*}
  \tan{\left\{ \alpha+ \left( \alpha-\beta \right) \right\}}
  &=\frac{\tan{\alpha}+\tan{\left( \alpha-\beta \right)}}{1-\tan{\alpha}\cdot\tan{\left( \alpha-\beta \right)}}\\
  &=\frac{2-8}{1-2\cdot(-8)}\\
  &=-\frac{6}{17}
\end{align*}
また,$y=2x$$2x+3y=6$の交点の座標は
\begin{align*}
 \left(
 \begin{array}{cc}
  2 & -1 \\
  2 & 3
 \end{array}
 \right)
&%
 \left(
 \begin{array}{c}
  x \\
  y
 \end{array}
 \right)
=
 \left(
 \begin{array}{c}
  0 \\
  6
 \end{array}
 \right)
%
& \left(
 \begin{array}{c}
  x \\
  y
 \end{array}
 \right)
%
&=\frac{1}{6+2}
%
 \left(
 \begin{array}{cc}
  3 & 1 \\
  -2 & 2
 \end{array}
 \right)
 \left(
 \begin{array}{c}
  0 \\
  6
 \end{array}
 \right)
\end{align*}
したがって求める図形は,$\left(\dfrac{3}{4},~\dfrac{3}{2}\right)$を通る傾き$-\dfrac{6}{17}$の直線なので
\begin{align*}
y-\frac{3}{2}&=-\frac{6}{17}\left( x-\frac{3}{4} \right) &
&\frac{1}{2}\left(2y-3\right)=-\frac{6}{17}\cdot\frac{1}{4}\left(4x-3\right)\\
17(2y-3)&=-3(4x-3) & &\therefore\quad 6x+17y-30=0
\end{align*}
と分かる.
\end{document}

採点業務を機械的にこなす

じぶんは足し算引き算などの数値計算が致命的なレベルで苦手なので,暗算で合計点を計算することができません.そのためにいくつか工夫をして合計点を算出しているのですが,それを公開します.

ただこのやり方は,大半の人にとっては面倒なだけだと思います ω

たとえば,大問が1から5まである試験の採点をすることを考えましょう.

以下のようなcsvファイルを用意します.

f:id:hohei3108:20171010180157p:plain

表計算ソフトで開くとこんな感じ(値が大きくて0になってます).

f:id:hohei3108:20171010180151p:plain

まずは,正答なら1,誤答なら0を打ち込みます.このとき,△なら適当なアルファベットに点数を対応させます(aは1点,bは2点としています).

f:id:hohei3108:20171010180209p:plain

次に,シェルスクリプトを使って数字の間にカンマを入れます.

f:id:hohei3108:20171010180215p:plain

これを,表計算ソフトで開くと以下のようになります.

f:id:hohei3108:20171010180220p:plain

あとは,配点分だけ列をかけます.

f:id:hohei3108:20171010180225p:plain

残ったアルファベットを置換して,合計点をだせば完了です.

f:id:hohei3108:20171010180234p:plain

ちなみに以下がカンマを入れるスクリプトです.comma.sh などと名前をつけて使ってください.

#!/bin/sh

target="$1"
targetwithoutext="${1%.csv}"
echo "target: $target"
echo "targetwithoutext: $targetwithoutext"

place=`dirname $target`
echo "place of target: $place"

cat $target | env -i sed -e 's/[a-z0-9]/,&/g' | env -i sed -e 's/,,*/,/g' | env -i sed -e 's/^[ ,][ ,]*//g' > "${targetwithoutext}-comma.csv"
~ $ ./comma.sh ~/Desktop/class.csv 

emacsの行番号の色を mozc入力モードで切替え

入力モードによってモードラインの色を切替えるものばかりが目につくのですが、設定が複雑なわりに視認性の向上に貢献してない気がします ω

以下の設定をinit.elなどに加えてください.

hlinum.el をつかってます.

https://github.com/tom-tan/hlinum-mode/blob/master/hlinum.el

(require 'hlinum)
(custom-set-variables '(global-linum-mode t))
;; 色の変更
(custom-set-faces
 '(linum-highlight-face ((t (:foreground "black"
                             :background "green2")))))
(hlinum-activate)


;; カーソルの色と形を入力モードにより変える
(add-hook 'input-method-activate-hook
          (lambda() (setq default-cursor-type 'hollow)
                    (custom-set-faces; hlinum の色変更
                     '(linum-highlight-face ((t (:foreground "black"
                                                 :background "magenta1")))))))

(add-hook 'input-method-inactivate-hook
          (lambda() (setq default-cursor-type 'box)
                    (custom-set-faces; hlinum の色変更
                     '(linum-highlight-face ((t (:foreground "black"
                                                 :background "green2")))))))

tikzで引く下線

f:id:hohei3108:20170923172214p:plain

\ubumps{あああ}\ucoil{あああ}\udot{あああ}\\
\usnake{あああ}\underline{あああ}\uzigzag{あああ}\\
\usnake{$\dfrac{1}{360}$}\uzigzag{$\dfrac{1}{360}$}\underline{$\dfrac{1}{360}$}ああああ

下のやつをプリアンブルなどに貼り付ければ,上の記述で下線が使えます.latexには多くの下線パッケージがあるのですが,どれも気に食わなかったので作りました ω

参考というかほとんどパクった記事↓ tex.stackexchange.com

\newcommand{\udot}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1.5pt,outer ysep=0pt,outer xsep=-2pt] (todotted) {#1};
        \draw[densely dotted,thick] (todotted.south west) -- (todotted.south east);
    }%
}%

\newcommand{\uzigzag}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1.2pt,outer ysep=0pt,outer xsep=-2pt] (todotted) {#1};
        \draw[decorate,decoration={zigzag,amplitude=0.2mm,segment length=1mm}] (todotted.south west) -- (todotted.south east);
    }%
}

\newcommand{\usnake}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1.5pt,outer ysep=0pt,outer xsep=-2pt] (todotted) {#1};
        \draw[decorate,decoration={snake,amplitude=0.2mm,segment length=1mm}] (todotted.south west) -- (todotted.south east);
    }%
}%

\newcommand{\ucoil}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1.5pt,outer ysep=0pt,outer xsep=-2pt] (todotted) {#1};
        \draw[decorate,decoration={coil,amplitude=0.2mm,segment length=1mm}] (todotted.south west) -- (todotted.south east);
    }%
}%

\newcommand{\ubumps}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1.5pt,outer ysep=0pt,outer xsep=-2pt] (todotted) {#1};
        \draw[decorate,decoration={bumps,amplitude=0.4mm,segment length=2mm}] (todotted.south west) -- (todotted.south east);
    }%
}%

tcolorbox でピカチュウフレーム

f:id:hohei3108:20171001002945p:plain

下の記述がピカチュウフレームが使える最低限の記述です.見苦しいところが多いので,気が向くかtikzが上達したら直します.

知識のある人が改善してくれたらうれしいです ω

\usepackage[most]{tcolorbox}

\tcbset{pikachu/.style={enhanced,colback=white,colframe=black,boxrule=0.6mm,enlarge top by=7.0mm,enlarge bottom by=2.0mm,top=50pt,sharp corners=south,arc=14mm,
overlay={
\begin{scope}[shift={([xshift=9.0mm,yshift=-13mm]frame.north west)},rotate=30]
% 左目
  \path[draw=black,fill=black,line width=0.5mm] (0,0) arc (0:360:2mm);
  \path[fill=white] (-.05,.08) arc (0:360:1mm);
% 右目
  \path[draw=black,fill=black,line width=0.5mm] (1.2,0) arc (0:360:2mm);
  \path[fill=white] (1.1-.05,.08) arc (0:360:1mm);
% ハナ
  \path[draw=black,fill=black] (0.4,-.15) circle [x radius=0.06,y radius=0.03] (0:360);
% クチ
  \path[draw=black,line width=0.4mm,xshift=0.5mm,yshift=-3.5mm] (0,-.02) .. controls (.1,-.1) and (.15,-.14) .. (.35,0) % 左
  .. controls (-.15+.7,-.14) and (-.1+.7,-.1) .. (0+.7,-.02); % 右
% ほっぺ
  \path[draw=black,fill=white,line width=0.4mm] (1.6,-0.4) arc (10:290:2mm);
\end{scope}}
,
underlay={
\begin{scope}[shift={([xshift=0mm,yshift=0mm]frame.north west)}]
% 耳とフレームが重なるところを白塗り(右)
  \path[draw=white,line width=0.7mm] (1.51,-0.03)--(2.55,-0.03);
% 耳とフレームが重なるところを白塗り(左)
  \path[draw=white,line width=2.0mm] (0.1,-0.84)--(0.1,-2);
\end{scope}}
,
% 右耳
underlay={
\begin{scope}[shift={([xshift=0mm,yshift=0mm]frame.north west)}]
% 耳のメイン
  \path[draw=black,fill=white,line width=0.6mm,rounded corners=1.0pt] (1.5,-0.03) .. controls (2.5,0.3) and (3.5,-0.5) .. (3.7,-0.6) .. controls (2.7,-0.5) and (2.5,-0.5) .. (2.2,-0.4);

% 耳の黒い部分の境界
  \clip (1.5,-0.03) .. controls (2.5,0.3) and (3.5,-0.5) .. (3.7,-0.6) .. controls (2.7,-0.5) and (2.5,-0.5) .. (2.2,-0.4);

  \fill[black] (2.4,-0.5) to [out=10,in=210] (3.4,-0.3) -- (4,-0.7) -- cycle;
\end{scope}}
,
% 左耳
underlay={
\begin{scope}[shift={([xshift=9.06mm,yshift=4.93mm]frame.north west)},rotate=60]
% 耳のメイン xscale=-1 で反転
  \path[xscale=-1,draw=black,fill=white,line width=0.6mm,rounded corners=1.0pt] (1.5,-0.03) .. controls (2.5,0.3) and (3.5,-0.5) .. (3.7,-0.6) .. controls (2.7,-0.5) and (2.5,-0.5) .. (2.2,-0.4);

% 耳の黒い部分の境界
  \clip[xscale=-1] (1.5,-0.03) .. controls (2.5,0.3) and (3.5,-0.5) .. (3.7,-0.6) .. controls (2.7,-0.5) and (2.5,-0.5) .. (2.2,-0.4);

  \fill[xscale=-1,black] (2.4,-0.5) to [out=10,in=210] (3.4,-0.3) -- (4,-0.7) -- cycle;
\end{scope}}
,
% しっぽ
underlay={
\begin{scope}
[xscale=1.1,yscale=0.4,shift={([xshift=-5mm,yshift=-19mm]frame.north east)},rotate=38]
% [xscale=1,yscale=1,shift={([xshift=-8mm,yshift=-50mm]frame.north east)},rotate=0]
% グリッド
% \draw [help lines] (-6,0) grid (6,6);
  \path[draw=black,fill=white,line width=0.6mm,rounded corners=1.0pt]
    (0,0) -- (0.3,0) -- (0.7,1.2) -- (-0.5,1.4) -- (-0.1,2.7) -- (-1.8,3) to [out=80,in=245] (-1,5.4) -- (-3.9,6) to [out=245,in=90] (-4.6,2.2) -- (-2,2) -- (-2.2,1.1) -- (0.2,0.7) -- cycle;

% 上とおなじの clip
  \clip (0,0) -- (0.3,0) -- (0.7,1.2) -- (-0.5,1.4) -- (-0.1,2.7) -- (-2,3) to [out=80,in=245] (-1.2,5.4) -- (-4.1,6) to [out=245,in=90] (-4.8,2.2) -- (-2.2,2) -- (-2.5,1.1) -- (0.2,0.7) -- cycle;
  \fill (-0.8,0.7) -- (-0.2,0.9) -- (-0.5,1.1) -- (-0.2,1.1) -- (-0.4,1.2) -- (-0.1,1.25) -- (-0.4,1.45)
    -- (1,1.5) -- (1,0) -- (-0.5,0) -- cycle;
\end{scope}}
,
% 背中の模様
underlay={
\begin{scope}[shift={(frame.north west)},rounded corners=10pt]
\path[fill=black,xshift=36mm,yshift=0mm] (0,0) -- (0.3,-0.8) -- (0.35,0);
\path[fill=black,xshift=42mm,yshift=0mm] (0,0) -- (0.3,-0.8) -- (0.35,0);
\end{scope}}
}}

\begin{document}
\begin{tcolorbox}[pikachu]
  \textbf{問題}\quad $\triangle$ABCにおいて,辺OAを$3:2$に内分する点をC,辺OBを$2:1$に内分する点をDとし,線分ADと線分BCの交点をPとする.
  $\overrightarrow{\mathrm{OA}}=\overrightarrow{a}$$\overrightarrow{\mathrm{OB}}=\overrightarrow{b}$とするとき,$\overrightarrow{\mathrm{OP}}$$\overrightarrow{a},\overrightarrow{b}$を用いて表せ.
\end{tcolorbox}
\end{document}