Notes Related With Softwares

Table of Contents

1 Emacs

1.1 Keyboard Shortcuts

Shortcut Function Shortcut Function
C-v Move forward one screenful C-a Move cursor to start of line
M-v Move backward one screenful C-e Move cursor to the end of line
C-x C-f Find File C-n Next Line
C-x C-s Save File C-Space Begin a selection
C-x C-w Save As C-w Cut region (kill region)
C-x C-c Quit Emacs M-w Copy region
C-g To quit a partially entered command C-y Paste (“yank”)
C-/ or C-x u Undo M-< Start of the Document
C-x 1 Delete all but one window M-> End of the Document
C-k Kill line from current point M-x RET goto-line Go to line number
C-s Incremental Search M-x doctor Emacs psychoterapist
C-r Seearch Backward M-; Comment out region
C-h t Help With Tutorial C-h f Describe Function
C-h v Describe Variable C-h k Describe Key
C-h a apropos (Help for string/regexp) C-h i Read Emacs Documentation
C-x b Switch Buffers C-x C-b Get a list of buffers
C-x 2 Split Screen Horizontally C-x 3 Split Window Right
C-x 1 Delete Other Windows C-x 0 Delete Current Window
C-x o Switch to Other Window C-x k Close File(Kill Buffer)
C-x right arrow Switch to next-buffer C-x left arrow Switch to previous buffer
C-x r-s-# Copy Selection to numbered clipboard C-x r-i-# Paste from number clipboard

1.2 In Emacs, how can I search for and replace text?

Emacs has two types of search and replace functions: unconditional and queried. Unconditional search and replace To perform an unconditional search and replace, press; M-x . Then enter:

replace-string RET(Enter)

your_search_string RET

your_replace_string

Replace your_search_string with the existing text string you want to find and remove, and replace your_replace_string with the new text you want to add in its place.

Queried search and replace

To do a queried search and replace (with a prompt for replacing each occurrence of a text string),press M-% . You will then be prompted for your search and replace strings. Emacs will find and display each occurrence of the search string and ask you for further instructions. You can respond with any of the following options:

Spacebar Replace text and find the next occurence
Del Leave text as is and find the next occurrence
. (period) Replace text, then stop looking for occurrences
! (exclamation point) Replace all occurrences without asking
^ (caret) Return the cursor to previously replaced text

If you type any other character, Emacs will stop looking for occurrences and execute the character as a command. To restart the queried search and replace, type:

C-x M- M-RET

1.3 How to run Shell Commands from Emacs

Emacs has commands for passing single command lines to inferior shell processes; it can also run a shell interactively with input and output to an Emacs buffer named shell or run a shell inside a terminal emulator window. There is a shell implemented entirely in Emacs, documented in a separate manual.

M-! RET

Run the shell command line cmd and display the output (shell-command).

M-x term

Run a subshell with input and output through an Emacs buffer. You can then give commands interactively. Full terminal emulation is available.

M-x eshell

Start the Emacs shell.

1.4 How to Update Packages in Emacs

First, to list all packages;

M-x list-packages

this will automatically resfresh the archive contents. Then;

U

to mark all upgradable packages to be upgraded. Then;

x

to perform the new updates. (This information is adapted from here)

1.5 Writing Modes for Emacs

One can use several writing modes for Emacs. To view the documentation for the current major mode, including a list of its key bindings, type;

C-h m (describe mode)

For instance;

Html Mode

When you open .html file, it is automatically opened in html mode.However to change it manually;

M-x html-mode

Emacs have different key shortcuts for each different modes

*Some Keyboard Shortcuts for HTML Mode~

C-c C-d Delete tags. (Put the cursor inside the tags)
C-c C-f Tag Forward. Make the cursor jump to ending tag.
C-c C-b Tag Backward. Make the cursor jump to beginning tag.
C-c C-v To preview in a browser.

(This information is adapted from here)

How to write in Bold, Underline etc. as in Word in Emacs

Emacs has a “facemenu-*” command. See the menu 〖Edit ▸ Text Properties ▸ Face〗. Here are the hotkeys.

M+o d Default
M+o b Bold
M+o i Italic
M+o I Bold-Italic
M+o u Underline
M+o o Other

To be able to save and restore you need to save in enriched-mode . To open Emacs in enriched mode;

M-x enriched mode

Also to highlight some phrases or expressions one can use the followings;

M-x highlight-phrase

M-x highlight-regexp

M-x highlight-lines-matching-regexp

(This information is adapted from here.)

1.6 How to install and use wolfram alpha mode in emacs

https://github.com/hsjunnesson/wolfram.el

Install package from melpa

M-x list-packages

Find wolfram-alpha then chhose the package to install via

I

Then to install the package

X

Then add this to your init file:

(require 'wolfram)

"Create an account at wolframalpha.com, then in your account select "My Apps (API)". Create a new AppID. In Emacs set that AppID as the custom variable wolfram-alpha-app-id."

I have AppID as : 3K4RRQ-3PQV87TE9X

M-x customize-save-variable wolfram-alpha-app-id 3K4RRQ-3PQV87TE9X

To make a query, run M-x wolfram-alpha then type your query. It will show the result in an org-mode buffer called WolframAlpha.

1.7 How to use Mathematica files (.m files) in Emacs? (Highlighting mode)

Wolfram mode needs to be installed for this purpose.

https://melpa.org/#/wolfram-mode

Things to do after installation:

This provides basic editing features for Wolfram Language " (http://reference.wolfram.com/language/), based on `math++.el'
(http://chasen.org/~daiti-m/dist/math++.el)."

You should add the followings to `~/.emacs.d/init.el'.

(autoload 'wolfram-mode "wolfram-mode" nil t)
(autoload 'run-wolfram "wolfram-mode" nil t)
(setq wolfram-program "/Applications/Mathematica.app/Contents/MacOS/MathKernel")
(add-to-list 'auto-mode-alist '("\\.m$" . wolfram-mode))

1.8 How do I reload a file in a buffer?

I usually work on files which are updated in the file system via version control. What's a quick way to reload a file without having to C-x C-f the file again and getting asked if I want to reload it?

M-x revert-buffer will do exactly what you want. It will still ask for confirmation.

Another option (my favorite) is the below function:

;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))

http://emacs.stackexchange.com/questions/169/how-do-i-reload-a-file-in-a-buffer

1.9 How can I get Emacs to reload all my definitions that I have updated in .emacs without restarting Emacs?

You can use the command load-file (M-x load-file, then press return twice to accept the default filename, which is the current file being edited).

You can also just move the point to the end of any sexp and press C-x C-e to execute just that sexp. Usually it's not necessary to reload the whole file if you're just changing a line or two.

Alternatively;

M-x eval-buffer

immediately evaluates all code in the buffer, its the quickest method, if your .emacs is idempotent.

http://stackoverflow.com/questions/2580650/how-can-i-reload-emacs-after-changing-it

1.10 How to Preserve Windows Layout in Emacs.

1.10.1 Using Emacs Desktop Library

You can save the desktop manually with the command M-x desktop-save.

You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: use the Customization buffer (see Easy Customization) to set desktop-save-mode to t for future sessions, or add this line in your init file (see Init File):

(desktop-save-mode 1)

https://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Saving-Emacs-Sessions.html

1.10.2 Winner Mode

Winner Mode is a global minor mode. When activated, it allows you to “undo” (and “redo”) changes in the window configuration with the key commands

C-c left and C-c right

Winner Mode is great when you depend a lot on working with Emacs windows. To read code, you want one window. To compare it with another file, you want two windows. When on IRC you want six windows, and while you’re engaging in an important discussion, you want just one window, etc. Getting from many windows to one window is easy: C-x 1 will do it. But getting back to a delicate WindowConfiguration is difficult. This is where Winner Mode comes in: With it, going back to a previous session is easy.

Activate it with M-x winner-mode RET or add the following to your ~/.emacs:

(winner-mode 1))

1.10.3 "Register" option

Use C-x r w <register> to store a window configuration in a register, and

C-x r j <register> (where <register> is a single character) to jump back to it.

1.11 How to cound Words and number of lines in Emacs

Select th region first then;

M-x count-words-region

1.12 Python Mode

1.12.1 How to change the default shell to python 3?

M-x customize-variable RET python-shell-interpreter RET

and change it to python3

Afterwards M-x run-python RET should open a Python3 shell. Or try C-c C-c

1.12.2 Use Elpy mode

https://elpy.readthedocs.io/en/latest/introduction.html

Install the package using list-packages. Then put the following; (package-initialize)
(elpy-enable)

in your .emacs file.

1.13 How to Change the filnames in a folder with Emacs

  • Use C-x d to enter dired and choose the directory with the files in
  • Use C-x C-q to turn dired into editing mode
  • Use M-% to replace foo with bar in the dired buffer. This will change the file names
  • Use C-c C-c to apply the changes or C-c ESC to cance

Also see; https://www.gnu.org/software/emacs/manual/html_node/emacs/Transforming-File-Names.html

1.14 How to save any or all buffers to their files

C-x s (save-some-buffers)

1.15 How to change the coding of the file system in emacs? (utf8 to windows-1251 for instance)

One should use the command set-buffer-file-coding-system (C-x RET f), set the encoding, and then save the file.

2 ORG MODE

2.1 Converting a region into a table

Org provides useful ways of converting a region into a table. For this, select a region and press C-c |. For example, press C-c | on this:

some, comma, separated, values

will automagically produce this:

some comma separated values

Usually, this command should be smart enough to guess what is the field separator for the region. If each line of the active region contains a TAB or a comma, it will assume this is the separator.

If you want to force the comma as a field separator, press C-u C-c |. If you want to force TAB as a field separator, press C-u C-u C-c |. If you want to force a specific number of spaces – say 3 – use C-u 3 C-c |.

http://orgmode.org/worg/org-tutorials/tables.html

2.2 New Line (Especially when exporting to html etc.)

Use \\ for new lines.

Or leave an empty line for new paragraphs.

2.3 Writing Source Codes in Org Mode

(defun org-xor (a b)
   "Exclusive or."
   (if a (not b) b))

#+BEGIN_SRC emacs-lisp
(defun org-xor (a b)
"Exclusive or."
(if a (not b) b))
#+END_SRC

See http://orgmode.org/manual/Working-With-Source-Code.html

2.4 How to comment out Lines

Lines starting with zero or more whitespace characters followed by one ‘#’ and a whitespace are treated as comments and, as such, are not exported.

Likewise, regions surrounded by ‘#+BEGIN_COMMENT’ ... ‘#+END_COMMENT’ are not exported.

Finally, a ‘COMMENT’ keyword at the beginning of an entry, but after any other keyword or priority cookie, comments out the entire subtree. In this case, the subtree is not exported and no code block within it is executed either1. The command below helps changing the comment status of a headline.

C-c ;

Toggle the ‘COMMENT’ keyword at the beginning of an entry.

This file is adapted from here.

2.5 Easy Templates

With just a few keystrokes, Org's easy templates inserts empty pairs of structural elements, such as #+BEGIN_SRC and #+END_SRC. Easy templates use an expansion mechanism, which is native to Org, in a process similar to yasnippet and other Emacs template expansion packages.

<<> <s> <TAB> completes the ‘src’ code block.

< l <TAB>

expands to:

#+BEGIN_EXPORT latex

#+END_EXPORT

Org comes with these pre-defined easy templates:

s #+BEGIN_SRC … #+END_SRC
e #+BEGIN_EXAMPLE … #+END_EXAMPLE
q #+BEGIN_QUOTE … #+END_QUOTE
v #+BEGIN_VERSE … #+END_VERSE
c #+BEGIN_CENTER … #+END_CENTER
l #+BEGIN_EXPORT latex … #+END_EXPORT
L #+LATEX:
h #+BEGIN_EXPORT html … #+END_EXPORT
H #+HTML:
a #+BEGIN_EXPORT ascii … #+END_EXPORT
A #+ASCII:
i #+INDEX: line
I #+INCLUDE: line

More templates can added by customizing the variable org-structure-template-alist, whose docstring has additional details.

http://orgmode.org/manual/Easy-templates.html#Easy-templates

2.6 How to add the screenshot images to emacs

2.6.1 First Method:

Use the following code which is adapted from: https://stackoverflow.com/questions/17435995/paste-an-image-on-clipboard-to-emacs-org-mode-file-without-saving-it

Save the following code into .emacs file.

(defun my-org-screenshot ()
  "Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
  (interactive)
  (org-display-inline-images)
  (setq filename
	(concat
	 (make-temp-name
	  (concat (file-name-nondirectory (buffer-file-name))
		  "_imgs/"
		  (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
  (unless (file-exists-p (file-name-directory filename))
    (make-directory (file-name-directory filename)))
  ; take screenshot
  (if (eq system-type 'darwin)
      (call-process "screencapture" nil nil nil "-i" filename))
  (if (eq system-type 'gnu/linux)
      (call-process "import" nil nil nil filename))
  ; insert into file if correctly taken
  (if (file-exists-p filename)
    (insert (concat "[[file:" filename "]]"))))

With this function if you want to add the screenshot image, then call

M-x my-org-screenshot

Then take the screenshot and it will automatically added to the org file. Then you can also call M-x image-mode to view the image. When you export the file into pdf for instance, image is also exported successfully. Moreover the image will be saved in the directory.

2.6.2 Second Method

One can also use the org-download package which can be found in melpa as well as from the following github page https://github.com/abo-abo/org-download

In .emacs file add the following line

(require 'org-download)

With this package you can drag and drop the images to the org file.

2.7 How to convert markdown language(.md) to org-mode?

This can be done using pandoc. Install it via

brew install pandoc

Then;

pandoc -f markdown -t org -o newfile.org original-file.markdown

see here.

2.8 How to convert(export) org file to markdown syntax?

Commands Function
C-c C-e m m (org-md-export-to-markdown) Export as a text file written in Markdown syntax. For an Org file, myfile.org, the resulting file will be myfile.md. The file will be overwritten without warning.
C-c C-e m M (org-md-export-as-markdown) Export to a temporary buffer. Do not create a file.
C-c C-e m o Export as a text file with Markdown syntax, then open it.

See here

2.9 Useful Packages

2.9.1 power thesaurus:

emacs-powerthesaurus is a simple plugin to integrate Emacs with amazing powerthesaurus.org.

https://github.com/SavchenkoValeriy/emacs-powerthesaurus

In order to install

M-x package-install [RET] powerthesaurus [RET]

2.9.2 osx-dictionary:

https://github.com/xuchunyang/osx-dictionary.el

In order to install;

M-x package-install RET osx-dictionary RET

2.10 Emphasis and Monospace and Code Syntax in text

You can make words bold, italic, underlined, verbatim and code, and, if you must, ‘+strike-through+’. Text in the code and verbatim string is not processed for Org mode specific syntax, it is exported verbatim.

(see https://orgmode.org/manual/Emphasis-and-monospace.html)

3 Vi

3.1 How to use visual blocks

BBBABB BBBABB BBBABB When on A, I'd go in block visual mode

ctrl-v select the lines you want to modify,

press I (insert mode with capital i),

and apply any changes I want for the first line. Leaving visual mode esc will apply all changes on the first line to all lines. This information is adapted from here

4 Open Suse

4.1 How to recover grub menu after installing OpenSuse to previously installed Windows8?

  • Type 'cmd' to search for the Shell.

Right click and launch as administrator.

  • Enter without the quotes;

"bcdedit /set {bootmgr} path \EFI\opensuse\shim.efi"

This information is from http://opensuseadventures.blogspot.com.tr/2014/02/dual-booting-with-windows-8-not-as.html

4.2 How to change Boot Priority in OpenSuse?

  • Open Yast
  • Under the Systems section, click Boot Loader
  • Click the Boot Loader Installation tab. Ensure that GRUB is displaying on the Boot Loader field and click Boot Loader Options.

5 Ubuntu

5.1 How to Learn Ubuntu Version From Terminal

5.2 How to Install a .deb file via the command line

To install a downloaded Debian package (.deb)

sudo dpkg -i packagename.deb

To remove a Debian package (.deb)

sudo dpkg -r packagename

To Reconfigure/Repair an installed Debian Package

sudo dpkg-reconfigure packagename

http://askubuntu.com/questions/40779/how-do-i-install-a-deb-file-via-the-command-line

5.3 How to Configure DNS Name Resolution From Terminal

Edit the resolv.conf document;

sudo emacs /etc/resolv.conf>

http://www.cyberciti.biz/faq/ubuntu-linux-configure-dns-nameserver-ip-address/

5.4 How to Create an Adminstrator User in Ubuntu

First create the user with;

sudo adduser

Then add a user to the sudo group with the command

sudo adduser sudo

http://superuser.com/questions/196848/how-do-i-create-an-administrator-user-on-ubuntu

5.5 How to Create and Add Members to the Group in Ubuntu?

To create group in ubuntu;

sudo groupadd "group_name"

To add members to the group ;

sudo usermod -a -G "group_name" "user_to _be_added"

How to give Read and Write Access to Group and Folder

sudo chgrp -R "group_name" "/path_to_the_directory"

sudo chmod -R 777 "/path_to_the_directory"

Note '777' is for read,write and execute. One can use 'g+rwxs' also instead of 777. See the File permissons note here. For Instance, I want to create a group called my_group and add users "Ali" and "Veli" to the group and finally want to have permission of rwx to the folder /var/www Then;

sudo groupadd throne

sudo usermod -a -G throne Veli

sudo chgrp -R throne /var/www

sudo chmod -R g+rwxs /var/www

or

sudo chmod -R 777 /var/www

5.5.1 How to List of Existed Groups on Ubuntu Server

To list all the groups, including ones used by the system

cat /etc/group

To list all the groups of which the current user is a member;

groups

6 MacOS

6.1 How to take a screen-shot?

Cmd-Shift-3 Take a screenshot of the screen, and save it as a file on the desktop
Cmd-Shift-4 Then select an area: Take a screenshot of an area and save it as a file on the desktop
Cmd-Shift-4 Then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
Cmd-Ctrl-Shift-3 Take a screenshot of the screen, and save it to the clipboard
Cmd-Ctrl-Shift-4 Then select an area: Take a screenshot of an area and save it to the clipboard
Cmd-Ctrl-Shift-4 Then space , then click a window: Take a screenshot of a window and save it to the clipboard

6.2 Iterm2 Shortcuts

Function Shortcut
Previous Tab Cmd + Left Arrow
Next Tab Cmd + Right Arrow
Go to Tab Cmd + number
Go to Window Cmd + Option + Number
Go to Split Pane by Direction Cmd + Option + arrow
Go to split Pane by order of Use Cmd + ]
Split Window Horizontally (same profile) Cmd + D
Split Window Vertically (same profile) Cmd + d
Set Mark Cmd + M
Jump to Mark Cmd + J

This information is adopted from https://gist.github.com/helger/3070258

6.3 How to name tabs in iterm2?

Put the following code in ~/.bash_profile

function title {
    echo -ne "\033]0;"$*"\007"
}

Then in terminal write the name

title "Name of the tab"

https://superuser.com/questions/419775/with-bash-iterm2-how-to-name-tabs

6.4 How to Open Current Folder in Finder from Terminal of Mac OS X

From the Mac Terminal, you can immediately open whatever folder or directory you are working within into the Finder of OS X by simply typing the following command:

open .

http://osxdaily.com/2009/11/30/open-current-folder-in-finder-from-the-terminal/

6.6 MacOS Useful Programs

6.6.1 Spectacle:

Used for Move and resize windows in MacOS

6.6.2 PDF Expert

Especially split view is very useful

6.6.3 Foxit Reader

6.6.4 Skim

6.6.5 Yoink

6.6.6 MindNode

6.6.7 f.lux

6.6.8 Keyboard Mastero Editor

6.6.9 Better Touch Tool

6.6.10 CleanMyMac

6.6.11 Amphetamine

6.6.12 LittleSnitch

6.6.13 Karabiner

6.6.14 Bartender

6.7 Latexit Problem

If Latexit does not render the command and even does not give any errors. Do the following.

Preferences -> Typesetting -> Ghostcript
alanina
/usr/local/bin/gs
girilmeli. Reset secenegi de otomatik olarak latex kurulumunun yerini bularak ayarlarinin yeniden yapmasini saglar.

6.8 How to remove all annotations in a pdf file with preview?

In the "Tools menu", choose "show inspector". In the inspector, select "Annotations inspector".

Press CMD+A to select all annotations, then click backspace to delete them

https://apple.stackexchange.com/questions/52222/preview-remove-all-annotations

7 Python

7.1 How to update a python package?

sudo pip install [package] --upgrade

For more info

7.2 How to list installed python packages?

pip freeze

or

yolk -l

for detailed package details.
Note that if the yolk is not installed; install it via

pip install yolk

For more info

7.3 How to update pip itself?

pip install --upgrade pip

For more info

7.4 Python Notes   PYTHON

7.4.1 new line character works in '\n' only.

For instance following works

#+BEGIN_SRC python print(name + ', You will be at the age of 100 in ' + str(yearwillbe100) + '\n') #+END_SRC python

but not this one

#+BEGIN_SRC python print(name + ', You will be at the age of 100 in ' + str(yearwillbe100) \n) #+END_SRC python

7.4.2 You cannot assign to a list like lst[i] = something. You need to use append.

lst.append(i)

(You could use the assignment notation if you were using a dictionary).

You can .append(element) to the list, e.g.: s1.append(i). What you are currently trying to do is access an element (s1[i]) that does not exist.

7.4.3 Ask user to enter a positive integer. If the value entered is not a positive integer, then keep asking.

# (The following part is necessary to test the user input number is a positive integer or not.)

while True:
    try:
	userNumber = int(input('Enter a positive integer number \n'))
    except ValueError:
	print('Try again! The number you entered is not integer')
	continue
    if userNumber <= 0:
	print('Try again! The number you entered is negative')
	continue
    else:
	break

7.4.4 Remarks

  • You should not have any statements in a function after the return statement. Once the function gets to the return statement it will immediately stop executing the function.
  • add # noqa to the end of long lines in order not to get the flake error too long warning
  • [::-1] -> used for reverse string ; for instance [5::-1] –> start from -1 to 5.
  • 20171107_225448_qrZfie.png
# generates random list with five numbers up to 30.
import random
random.sample(range(30),5)

#list can be concatanated
a = [1, 2, 3]
b = [d, e, f]
c = a + b 
# c = [ 1, 2, 3, d, e, f]

#list can be sorted
list.sort() 
  • input
input("%s, do yo want to choose rock, paper or scissors?" % user1)

7.4.5 Example Code

The notation is important. Fluke 8 does not give warning in this case.

"""Automate the boring staff:Chapter5."""

stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}


def displayInventory(inventory):
    """Count the items."""
    print("Inventory:")
    item_total = 0
    for k, v in inventory.items():
	item_total = item_total + v
	print(v, k)
    print("Total number of items: " + str(item_total))


displayInventory(stuff)


def addToInventory(inventory, addedItems):
    """Solve the second part."""
    for i in range(len(addedItems)):
	inventory.setdefault(addedItems[i], 0)
	inventory[addedItems[i]] = inventory[addedItems[i]] + 1
    return inventory


inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)

8 Mathematica

8.1 Path for External Applications

To learn the directory in Mathematica execute the following commands:
For global installation

$BaseDirectory

For user based installation;

$UserBaseDirectory

In general; Linux:

  • system-wide installation (requires root priviledges):

    usr/share/Mathematica/Applications

  • single-user installation:

    $HOME/.Mathematica/Applications/

Mac OS:

  • system-wide installation (requires root priviledges):

    Library/Mathematica/Applications

  • single-user installation:

    Users/<user>/Library/Mathematica/Applications

MSWindows:

  • system-wide installation:

    C:\Documents and settings\All Users\Application data\Mathematica\Applications\

  • single-user installation:

    C:\Documents and settings\<user>\Application Data\Mathematica\Applications\

Beware that in Windows these directories might be hidden!

8.2 How to Delete All Output Cells

First Way (From the Menu) In menu bar;
Cell->Delete All Output

Second Way (Command Line)

NotebookFind[SelectedNotebook[], "Output", All, CellStyle]; FrontEndExecute[FrontEndToken["Clear"]]

Third Way Alt + Click the one of the output line
This selects all output cells. Then
Delete all lines.

Also in order to select all input lines one can
Alt + Click the one of the input cell

8.3 Save Plot Options of Mathematica into a single variable

opts = {PlotRange -> All, PlotStyle -> Red};
Plot[x^2, {x, 0, 1}, Evaluate[opts]]

http://stackoverflow.com/questions/22184011/save-plot-options-of-mathematica-into-a-single-variable

8.4 How to Quit Kernel with command

Quit[]

8.5 How to import one notebook file into other?

For instance I want to define a notebook file that contains constant values and then use that values for different .nb files.

  • I have a long nb file. I want to subdivide different sections into separate smaller nb files and call and run them in a common nb file. How do I achieve this?
  • If you want to keep it as a *.nb file then try using the following in your main notebook,
nb1 = NotebookOpen[filename];
SelectionMove[nb1, All, Notebook]
SelectionEvaluate[nb1]

This will open the notebook "filename", select all the elements of the notebook and then run them. You could also include an extra line,

NotebookClose[nb1]

at the very end of the notebook "filename.nb" so that it closes itself once it has finished running. Then you have all the expressions in your kernel and you can continue to do some calculations.

Another option is as follows:

  • you can mark your cells as initilization cells (right click on the brackets -> initialization cell) and save it as a package (.m file).

    You can automatically save it as a package file by going into "Format -> Option Inspector", select "Selected Notebook" in "Show option values" goto "Notebook Options -> File Options" and set "AutoGeneratePackage" to "Automatic".

Import this .m file by the command Get["file"].

However this option has the disadvantage of reading code. But you see, the .m files are written in the standardform (I mean the way we write it in fortran). To me, the greatest advantage of .nb file is that we can write the expressions as printed in the book. So it is very easy to detect a mistake in .nb file. So I was wondering whether smaller .nb files can be called inside another .nb using Get.

(https://www.researchgate.net/post/Importing_and_running_nb_file_inside_another_in_mathematica2)

9 FeynCalc

9.1 FourDivergence

FourDivergence[exp, FourVector[p, mu]] calculates the partial derivative of exp w.r.t. p(mu). FourDivergence[exp, FourVector[p, mu], FourVector[p,nu], …]gives the multiple derivative.

Examples:
FourDivergence[FV[x, \[Beta]], FV[x, \[Delta]]]
Out: \(\bar{g}^{\beta \delta }\)

FourDivergence[FV[x, \[Beta]]/SP[x, x], FV[x, \[Delta]]] // FullSimplify

Out: \(\frac{\bar{x}^2 \bar{g}^{\beta \delta }-2 \bar{x}^{\beta +\delta }}{\bar{x}^4}\)

9.2 Kronecker Delta in Feyncalc

Since FeynCalc doesn't distinguish between upper and lower Lorentz indices, Kronecker delta and Minkowski metric are essentially represented by the same object.

Contract[MT[u, v] FV[x, v]]

returns the correct result instead of

Contract[KroneckerDelta[u,v] FV[x,v]]

http://mathematica.stackexchange.com/questions/80360/kronecker-delta-and-contraction-in-feyncalc

10 Tracer

Mathematica implementation of gamma-algebra in arbitrary space-time dimensions according to the Hooft-Veltman scheme. The Tracer package is capable of doing purely algebraic manipulations as well as trace operations on strings of gamma-algebra objects. In addition, it provides a set of utility functions for reordering, simplifying, and improving the readability of the output, including optional TeX formatted output. This package is intended as a computerized aid to a researcher working on higher-order corrections in relativistic quantum field theories. For the related web page see.

10.0.1 How to use Tracer

  • First install the related package (Tracer.m) from the web page above. However, since it is an old package there are some errors you encounter when you use Mathematica 10 or latest versions. Hence, I advise you to download the package here.
  • Open a Mathematica notebook
  • First import the Tracer.m package to your notebook

Import["location of the file(Tracer.m)"] Then you can use the functions defined in that package. The manual is given here.

11 Cadabra

11.1 How to install in MacOS

(Always check the installation instructions for new versions) Cadabra builds with the standard Apple compiler, but in order to build on OS X you need a number of packages from Homebrew (see http://brew.sh). Install these packages with::

brew install cmake boost pcre gmp python3
brew uninstall boost-python
brew install boost-python --with-python3
brew install pkgconfig
brew install gtkmm3 adwaita-icon-theme
sudo pip3 install sympy

The uninstall of boost-python in the 2nd line is to ensure that you have a version with python3 support. If the lines above prompt you to install XCode, go ahead and let it do that.

You also need a TeX installation such as MacTeX, http://tug.org/mactex/ . Any TeX will do, as long as 'latex' and 'dvipng' are available. Make sure to install TeX before attempting to build Cadabra, otherwise the Cadabra style files will not be installed in the appropriate place. Make sure 'latex' works from the terminal in which you will build Cadabra.

You need to clone the cadabra2 git repository (if you download the .zip file you will not have all data necessary to build). So do::

git clone https://github.com/kpeeters/cadabra2 After that you can build with the standard::

cd cadabra2
mkdir build
cd build
cmake ..
make
sudo make install

This will produce the command line app ``cadabra2`` and the Gtk notebook interface ``cadabra2-gtk``.

I am still planning a native OS X interface, but because building the Gtk interface is so easy and the result looks relatively decent, this has been put on hold for the time being.

Feedback from OS X users is very welcome because this is not my main development platform.

11.2 Beginners Guide

  • lines ending in a semi-colon get their output printed, while those ending in a period do not.
  • Cadabra often needs to know a bit more about properties of tensors or other symbols. Such properties are entered using the '::' symbol.

A simple example is the declaration of index sets, useful for automatic dummy index relabelling.

12 xAct

xAct is a suite of free packages for tensor computer algebra in Mathematica. xAct implements state-of-the-art algorithms for fast manipulations of indices and has been modelled on the current geometric approach to General Relativity. It is highly programmable and configurable. Since its first public release in March 2004, xAct has been intensively tested and has solved a number of hard problems in GR.

12.1 Installation

wget http://www.xact.es/download/xAct_1.1.2.tgz

Untar the folder via tar zxvf "name of the file".
Move the folder to tha basedirectory of mathematica which is for MacOS;
/Library/Mathematica

To learn the location of the base directory see Mathematica above.

The packages can be loaded using unix style

<<xAct/xTensor.m

or Mathematica style

<<xAct`xTensor`

13 DsixTools

The Standard Model Effective Field Theory Toolkit We present DsixTools, a Mathematica package for the handling of the dimension-six Standard Model Effective Field Theory. Among other features, DsixTools allows the user to perform the full one-loop Renormalization Group Evolution of the Wilson coefficients in the Warsaw basis. This is achieved thanks to the SMEFTrunner module, which implements the full one-loop anomalous dimension matrix previously derived in the literature. In addition, DsixTools also contains modules devoted to the matching to the ΔB=ΔS=1,2 and ΔB=ΔC=1 operators of the Weak Effective Theory at the electroweak scale and their QCD and QED Renormalization Group Evolution below the electroweak scale.

For the related arxiv article:

Here.

14 Git Notes

14.1 Git Command Line Instructions

Run the followings first

git config --global user.name 'sbilmis'
git config --global user.email 'sbilmis@metu.edu.tr'
git config --global color.ui 'auto'

Your settings will be seen in ~/.gitconfig file.

Help commands

git help <verb>
man git-<verb>
git <verb> -h #For a quick refresher
tldr git-<verb>

Go to the folder you want to initialize git and then run

git init

This will create a folder .git that contains all of your necessary repository files in the folder.

The main tool you use to determine which files are in which state is the git status command.

git status 
git status -s 
git status --short
git add my_file1 my_file2  
git clone https://..
#.gitignore file example

# ignore all .a files 
*.a

# but do track lib.a, even though you're ignoring .a files above 
!lib.a

# only ignore the TODO file in the current directory, not subdir/TODO 
/TODO

# ignore all files in the build/ directory 
build/

# ignore doc/notes.txt, but not doc/server/arch.txt 
doc/*.txt

# ignore all .pdf files in the doc/ directory and any of its subdirectories 
doc/**/*.pdf

See https://github.com/github/gitignore for gitignore templates.

git diff
gitt diff -cached
git diff --staged
git diftool
git difftool --staged
git difftool --tool-help

git rm –cached my_file1

git commit -m "My first comment"

git status

git diff my_file1

git add -u ; to add all the tracked files

git commit

git log

14.2 Gitlab

Start reading https://gitlab.com/help/ssh/README#locating-an-existing-ssh-key-pair

Create new ssh_key name and name as id_dsa

ssh-keygen -t rsa -C "selcukbilmis@gmail.com" -b 4096

Then copy the public SSH key as we will need it afterwards.

pbcopy < ~/.ssh/id_rsa.pub

The final step is to add your public SSH key to GitLab.

Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'. Use an identifiable title like 'Work Laptop - Windows 7' or 'Home MacBook Pro 15'.

If you manually copied your public SSH key make sure you copied the entire key starting with ssh-rsa and ending with your email.

If you used a non-default file path for your GitLab SSH key pair, you must configure your SSH client to find your GitLab private SSH key for connections to your GitLab server (perhaps gitlab.com).

For your current terminal session you can do so using the following commands (replacing other_id_rsa with your private SSH key):

Git Bash on Windows / GNU/Linux / macOS:

eval $(ssh-agent -s)
ssh-add ~/.ssh/other_id_rsa

15 New Installation of MacOs

15.1 Create .bash_profile

  • From terminal type

touch .bash_profile

15.2 Install Homebrew Cask

15.2.1 Emacs

brew install emacs --cocoa --rgb --with-gnutls brew linkapps

  • To open emacs in external windows define followings in .bash_profile

alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs" alias ec="/Applications/Emacs.app/Contents/MacOS/Emacs" alias emnw="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"

15.2.2 Appcleaner (To uninstall programs)

15.2.3 Iterm2

brew cask install iterm2

15.2.4 Kindle

brew cask install kindle

15.2.5 Djvu

brew cask install djvu

15.2.6 Java

brew cask install java

15.2.7 Jaxo Draw

15.2.8 Little Snitch

15.2.9 Sizeup

15.2.10 Better Touch Tool

15.2.11 Kaleidoscope

15.2.13 Unarchiver (From Appstore)

15.2.14 TeXLive

15.2.15 Amphetamine (From Appstore)

15.2.16 Skim

15.2.17 Zotero

15.2.18 Logitech Options (MX Master)

15.2.19 Jdownloader

15.2.20 Acrobat Pro

15.3 Terminal Appearance (Colorful ls command etc.)

http://osxdaily.com/2013/02/05/improve-terminal-appearance-mac-os-x/

In .bash_profile add the following lines;

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " export CLICOLOR=1 export LSCOLORS=ExFxBxDxCxegedabagacad alias ls='ls -GFh'

The first line changes the bash prompt to be colorized, and rearranges the prompt to be “username@hostname:cwd $”

The next two lines enable command line colors, and define colors for the ‘ls’ command

Finally, we alias ls to include a few flags by default. -G colorizes output, -h makes sizes human readable, and -F throws a / after a directory, * after an executable, and a @ after a symlink, making it easier to quickly identify things in directory listings.

Another Documentation: https://www.cyberciti.biz/faq/apple-mac-osx-terminal-color-ls-output-option/

  1. CLICOLOR – Use ANSI color sequences to distinguish file types.
  2. LSCOLORS – The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR

Understanding LSCOLORS values

You can define color for each attribute with the help of LSCOLORS, when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color. The default value is:

exfxcxdxbxegedabagacad

Where, ls Attribute Foreground color Background color directory e x symbolic f x socket c x pipe d x executable b x block e g character e d executable a b executable a g directory a c directory a d

The color and their code values are as follows: Code Meaning (Color) a Black b Red c Green d Brown e Blue f Magenta g Cyan h Light grey A Bold black, usually shows up as dark grey B Bold red C Bold green D Bold brown, usually shows up as yellow E Bold blue F Bold magenta G Bold cyan H Bold light grey; looks like bright white x Default foreground or background

export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced

15.4 Change Hostname, Local Hostname and Computer name

15.4.1 Set ComputerName in OS X with scutil

ComputerName is the so-called “user-friendly” name for the Mac, it’s what will show up on the Mac itself and what will be visible to others when connecting to it over a local network. This is also what’s visible under the Sharing preference panel. scutil --set ComputerName "MacBook Willy"

15.4.2 Set HostName in OS X with scutil

HostName is the name assigned to the computer as visible from the command line, and it’s also used by local and remote networks when connecting through SSH and Remote Login. scutil --set HostName "centauri"

15.4.3 Set LocalHostName in OS X with scutil

LocalHostName is the name identifier used by Bonjour and visible through file sharing services like AirDrop scutil --set LocalHostName "MacBookPro"

Of course there’s nothing wrong with using the same name for each example as well, which is actually the default behavior of OS X.

Finally, you can also check the current settings of LocalHostName, HostName, and ComputerName by using scutil with the –get flag like so: scutil --get HostName For that example, the HostName will be reported back, and if one is not set it will tell you.

15.5 Emacs

15.6 To install org mode

M-x list-packages Find org in the list I to choose the package to be installed X to execute the installation

15.7 To add melpa package repositories

https://melpa.org/#/getting-started Add following lines to .emacs file

;; To install marmalade packages (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) (package-initialize) ;;;;;

15.8 To install zen-burn theme

M-x package-install RET zenburn-theme To activate it; M-x load-theme RET zenburn

15.8.1 To make it permanent

Add following line to your .emacs (load-theme 'zenburn)

Author: sbilmis

Created: 2020-11-10 Tue 11:42

Validate