Notes on mac in the year of 2018


In [ ]:

Author: Yue-Wen FANG

Contact: fyuewen@gmail.com

Revision history: created in 11th, January, at Kyoto

1. Install mactex

brew tap caskroom/cask

这里会要求你输入一个密码,假设ABCD

brew cask install mactex

第二个命令会下载安装文件,此刻你可以去喝杯咖啡或者喝杯茶。当然你也可以选择继续埋头工作。下载后自动安装,然后会要求你一个密码,你可以输入ABCD

然后重新打开一个terminal,happy playing with it...

笔记中的部分内容在我的豆瓣日记中也会有提及,不过豆瓣大多是我随手一记的东西,很难去回头在看它们。

2. Install xcrysden in mac

In Ubuntun, it's quite easy to install xcrysden. First, sudo apt-get install xorg openbox; second, sudo apt-get install xcrysden

However, in mac, it's a bit more comlicated.

In mac os, we need install xQuartz (to set xQuartz as the default x11 system, we have to logout and login mac again) to get a x11 system, in addition, you need install xcode.

Then download and install MacPorts: https://www.macports.org/install.php

Then use command 'xcode-select --install' and 'xcodebuild -license'

Finally, "port install xcrysden +x11"

Now, it's ready to go...

3. Open svg file and export it as pdf

Date: 20180614

Recently, I ploted a 3D energy profile using Wolfram Mathematica 11 for one of my research papers. For 3D figures, Mathematica cannot export vector PDF. To further retouch my figure, I exported the rastered PDF from Mathematica, and imported it into Inkscape (I used Inkscape in a Windows system). After adding some text and labels to the figure, I found the 3D colored part in the figure will be vanished if I exported it into PDF from Inkscape.

To solve this problem, I installed Gapplin, and opend the svg file which is the native format for Inkscape, this software can export it into tif, pdf and png with high quality. When output format is png, the solution can be tunned. When output is pdf, the figure will be vector-like

4. Install Inkscape in Mac OS

Date: 20180615

  • Press Command+Space and type Terminal and press enter/return key.

  • Run in Terminal app:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null

and press enter/return key. If the screen prompts you to enter a password, please enter your Mac's user password to continue. When you type the password, it won't be displayed on screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.

  • Run:

brew cask install inkscape

Note that XQuarts should be installed before installing inkscape.

It may take seceral minitues for lauching Inkscape on Mac for the first time because of the caching fonts from the computer.

4.1 Make figure background 'transparent'

There are some filters available in Inkscape which can speed up complicated tasks.

For instance, i wanted to remove white background of an image to make it transparent. I used the following method / filter in Inkscape.

Select the image object.

For versions < 0.91 Go to Filters -> Transparency Utlities -> Light Eraser For version 0.91 Go to Filters > Fill & Transparency > Light Eraser

Ref: https://graphicdesign.stackexchange.com/questions/15450/remove-background-based-on-color-in-inkscape/28285#28285?newreg=97f1e5a90c444d09bdb117d51e5b7636

5. Mindmap software in Mac

Freeplane, although not perfect, but it's free and not difficult to use.

6. Wrting tools like Ulysses

I found MAC app has some productivity writing tools like commercial software Ulysses. It can help focusing on writing.

7. Open a file using a specified application/software

open -a Typora README.md

Here, Typora is a writing application supporting markdown, and README.md is a markdown text.

8. Install mactex

brew tap caskroom/cask

这里会要求你输入一个密码,假设ABCD

brew cask install mactex

第二个命令会下载安装文件,此刻你可以去喝杯咖啡或者喝杯茶。当然你也可以选择继续埋头工作。下载后自动安装,然后会要求你一个密码,你可以输入ABCD

然后重新打开一个terminal,happy playing with it...

9. Vim open file at the position of last open

对于没有特意设置过的mac os系统,每次vim打开文件都是从第一行开始。为了让vim记住上一次打开的地方。可以修改~/.vimrc 加入以下两行:

au BufWinLeave * mkview

au BufWinEnter * silent loadview

参考文献:https://stackoverflow.com/questions/774560/in-vim-how-do-i-get-a-file-to-open-at-the-same-line-number-i-closed-it-at-last

10. Install julia

I know two methods to install julia

  • Command line method

brew update

brew tap staticfloat/julia

brew install julia

  • dmg installation method

Just download the official dmg (see https://julialang.org/downloads/), and install it as other applications in mac os.

11. Download YouTube videos through youtube-dl command

Install youtube-dl from its github page. Use the command "youtube-dl URL" to download the requested video.

12. Install gfortran

Please read Gfortran for MacOSX 10.10 (Yosemite) to 10.13 (High Sierra) systems

Xcode is needed, then download gfortra dmg file, install it.

I installed it by following it, but got errors: I don't understand 'm' flag

The solution is here:

$ cd /opt/local/bin

$ sudo mv ./as ./as-broken

$ sudo ln -s /usr/bin/as ./as

13 /must>not&exist/foo:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative use

For me, when using python 3.6, or python 3.7 or python 2.7, I alwalys got this warning when open python scripts using vim. I have used the latest vim version: Patch 8.1.0201 of vim, and I also have following settings in my .vimrc file:

if has('python3') && !has('patch-8.1.201') silent! python3 1 endif

I couldn't remove this warning as others: see https://github.com/vim/vim/issues/3117

I got a workaround by: let g:pymode = 0 setlocal complete+=t setlocal formatoptions-=t "if v:version > 702 && !&relativenumber " setlocal number "endif setlocal nowrap setlocal textwidth=79 setlocal commentstring=#%s setlocal define=^\s*$def\\\\|class$

About the usage of let g:pymode, plese see https://github.com/python-mode/python-mode/issues/356

14 Install Mayavi in mac Mojave

Ref: https://apple.stackexchange.com/questions/287200/how-do-i-install-mayavi-for-my-python3-on-macos-sierra

Firstly, let's build a virtual environment:

conda create --name myenv python=3 Secondly, activate the environment named 'myenv', and update the conda via:

conda update -n base conda Thirdly,

brew install vtk --with-python3 --without-python Finally,

conda install -c anaconda mayavi

An example code to generate the animation:

(the orginal source code of this example comes from the official website)


In [ ]:
#!/usr/bin/env python3                                                                               

from mayavi import mlab
from tvtk.tools import visual
from vtk.util import colors as color

# Create a figure                                                                                    
f = mlab.figure(size=(500,500))
# Tell visual to use this as the viewer.                                         
visual.set_viewer(f)

# A silly visualization.                                                                             
mlab.test_plot3d()

# Even sillier animation.                                                                            
b1 = visual.box()
b2 = visual.box(x=4., color=color.red)
b3 = visual.box(x=-4, color=color.red)
b1.v = 5.0

@mlab.show
@mlab.animate(delay=250)
def anim():
    """Animate the b1 box."""
    while 1:
        b1.x = b1.x + b1.v*0.1
        if b1.x > 2.5 or b1.x < -2.5:
            b1.v = -b1.v
        yield

# Run the animation.                                                                                 
anim()

15 Text messages to your cellphone and gmail via python

I didn't test this library named smtplib very carefully, howevery, I believe it can work. I will come back to visit it at a proper time.

Ref: https://patrickfuller.github.io/texting-from-your-server-in-python/

16 Install pov

  1. Run in Terminal app: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

  2. brew install povray

Ref: http://macappstore.org/povray/

You can use the command "$which povray" to check where the povray is.

In my mac, the povray is in:

/usr/local/bin/povray

and the corresponding include files are in:

/usr/local/Cellar/povray/3.7.0.8_1/share/povray-3.7/include

17 Allow Apps from Anywhere in macOS GateKeeper, and install 'Art Of Illusion'

Since macOS Sierra, the menu Security & Privacy only display two options, i.e. 1) App Store 2) App Store and identified developers.

However, install some softwares may require higher authority, we hence need allow the apps from anywhere.

For example, the installation of 'Art Of Illusion 3.0.3' requires this enabled. If you don't allow the Apps to be from anywhere, the mac will remind you that this source package is damaged (however, it's wrong, see: http://www.artofillusion.org/downloads)

Here is the method of enable it:

  1. Quit out of System Preferences

  2. Open the Terminal app from the /Applications/Utilities/ folder and then enter the following command syntax: sudo spctl --master-disable

  3. Hit return and authenticate with an admin password

  4. Relaunch System Preferences and go to “Security & Privacy” and the “General” tab

  5. You will now see the “Anywhere” option under ‘Allow apps downloaded from:’ Gatekeeper options

Then you can install the applications.

Howver, I recommend disabling it after installation to make macOS safe: sudo spctl --master-enable

Ref: http://osxdaily.com/2016/09/27/allow-apps-from-anywhere-macos-gatekeeper/

18 Install restview and use it to visualize the reStructuredText

  1. pip install restview

  2. restview file.rst

19 Install xcrysden in MAC via macports

XCrySDen has been ported on macports by David Strubbe. It can be installed using following steps.

  1. Install a compatible version of macports software using 3 steps given in the following link:

https://www.macports.org/install.php

  1. Install XCrySDen using following command

sudo port install xcrysden +x11 (Note that this step requies Xcode command line tool, see section 20)

  1. Add the following lines in .bash_profile file
XCrySDen

export XCRYSDEN_TOPDIR=/opt/local/share/xcrysden-1.5.60 export XCRYSDEN_SCRATCH=/tmp

  1. Open a new terminal window and execute command

xcrysden

20 Install Xcode command line tool

Method 1. We can install xcode first, and then install Xcode command line from the preferences.

Method 2 (highly recommend): MacPorts users who do not wish to install the very large Xcode suite can install GCC via "Command Line Tools for Xcode" from https://developer.apple.com/downloads/index.action

Ref: https://github.com/astrofrog/macports-python/issues/5

21 Change font in LateXiT

Ref: http://dm5ms.blogspot.com/2015/10/using-sansserif-fonts-in-latexit.html

Open preferences of LateXiT, and create a new configuration. Copy the following content to the "Preambles"


In [ ]:
\documentclass[10pt]{article}
\usepackage[usenames]{color} %used for font color
\usepackage{amssymb} %maths
\usepackage{amsmath} %maths
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{helvet}
\usepackage{sfmath}
\renewcommand*{\familydefault}{\sfdefault}\usepackage[usenames,dvipsnames]{xcolor}
\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}