├── .devcontainer.json
├── .github
└── workflows
│ └── pretext-cli.yml
├── .gitignore
├── GenerateAssetsHelp.md
├── LICENSE.md
├── README.md
├── assets
├── first-notebook.ipynb
├── g4m.png
├── g4m.svg
├── git-branches-source.xml
├── git-branches.png
├── screenshots
│ ├── codespace-explorer-newfile.png
│ ├── codespace-preview-md.png
│ ├── codespace-python-extension.png
│ ├── codespace-python-script.png
│ ├── codespace-timeout-retention.png
│ ├── copilot-icon.png
│ ├── github-codespace.png
│ ├── github-com.png
│ ├── github-dev.png
│ ├── pages-actions.png
│ ├── pages-setting.png
│ └── pages-template.png
├── website-example.html
└── website-example.zip
├── project.ptx
├── publication
└── publication.ptx
├── requirements.txt
├── site
└── CNAME
└── source
├── ax-additional-topics.ptx
├── ax-related.ptx
├── ch-coding.ptx
├── ch-collaboration.ptx
├── ch-copilot.ptx
├── ch-first-repo.ptx
├── ch-git-github.ptx
├── ch-jupyter.ptx
├── ch-manim.ptx
├── ch-projects.ptx
├── ch-website.ptx
├── colophon.ptx
├── frontmatter.ptx
├── main.ptx
└── pr-acknowledgements.ptx
/.devcontainer.json:
--------------------------------------------------------------------------------
1 | //
2 | // (delete the above line to manage this file manually)
3 | //////////////////////////////////////////////////////////////
4 | //
5 | // This file provides configuration options so that a PreTeXt
6 | // project can be edited and built using GitHub's Codespaces.
7 | // It is recommended to keep this in your repository even if you
8 | // do not use this feature, as it will allow other to explore
9 | // your project easily.
10 | // This file will be automatically generated by PreTeXt with the
11 | // latest updates unless you remove the first comment line above.
12 | //
13 | ///////////////////////////////////////////////////////////////
14 | {
15 | "name": "PreTeXt-Codespaces",
16 |
17 | // This Docker image includes some LaTeX support, but is still not to large. Note that if you keep your codespace running, it will use up your GitHub free storage quota. Additional options are listed below.
18 | // "image": "oscarlevin/pretext:small",
19 | // If you need to generate more complicated assets (such as sageplots) or use additional fonts when building to PDF, comment out the above line and uncomment the following line.
20 | "image": "oscarlevin/pretext:full",
21 | // If you only intend to build for web and don't have any latex-image generated assets, you can use a smaller image:
22 | // "image": "oscarlevin/pretext:lite",
23 |
24 | // Add gh cli as a feature (to support codechat)
25 | "features": {
26 | "ghcr.io/devcontainers/features/github-cli:1": {}
27 | },
28 |
29 | // Respect the project's designated dependencies
30 | "postCreateCommand": "pip install -r requirements.txt",
31 |
32 | // Port forwarding
33 | // ---------------
34 | // This is needed by the CodeChat Server.
35 | "forwardPorts": [
36 | // The port used for a Thrift connection between the VSCode CodeChat
37 | // extension and the CodeChat Server.
38 | 27376,
39 | // The port used for an HTTP connection from the CodeChat Client to
40 | // the CodeChat Server.
41 | 27377,
42 | // The port used by a websocket connection between the CodeChat
43 | // Server and the CodeChat Client.
44 | 27378
45 | ],
46 | // See the [docs](https://containers.dev/implementors/json_reference/#port-attributes).
47 | "portsAttributes": {
48 | "27376": {
49 | "label": "VSCode extension <-> CodeChat Server",
50 | "requireLocalPort": true
51 | },
52 | "27377": {
53 | "label": "CodeChat Client",
54 | "requireLocalPort": true
55 | },
56 | "27378": {
57 | "label": "CodeChat Client<->Server websocket",
58 | "requireLocalPort": true
59 | // This port needs to be public; however, there's no way to specify port visibility here. See `server.py` in the CodeChat Server for details.
60 | }
61 | },
62 |
63 | // Configure tool-specific properties.
64 | "customizations": {
65 | "codespaces": {
66 | "openFiles": ["source/main.ptx"]
67 | },
68 | "vscode": {
69 | "settings": {
70 | "editor.quickSuggestions": {
71 | "other": "off"
72 | },
73 | "editor.snippetSuggestions": "top",
74 | "xml.validation.enabled": false,
75 | "CodeChat.CodeChatServer.Command": "CodeChat_Server"
76 | },
77 | "extensions": [
78 | "ms-vscode.live-server",
79 | "oscarlevin.pretext-tools",
80 | "CodeChat.codechat"
81 | ]
82 | }
83 | }
84 |
85 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
86 | // "remoteUser": "root"
87 | }
88 |
--------------------------------------------------------------------------------
/.github/workflows/pretext-cli.yml:
--------------------------------------------------------------------------------
1 | #
2 | # (delete the above line to manage this file manually)
3 |
4 | name: PreTeXt-CLI Actions
5 | on:
6 | # Runs on pull requests
7 | pull_request:
8 | branches: ["*"]
9 | # Runs on pushes to main
10 | push:
11 | branches: ["main"]
12 | # Runs on demand
13 | workflow_dispatch:
14 |
15 | jobs:
16 | build:
17 | runs-on: ubuntu-latest
18 | container: oscarlevin/pretext:full
19 |
20 | steps:
21 | - name: Checkout source
22 | uses: actions/checkout@v4
23 |
24 | - name: install deps
25 | run: pip install -r requirements.txt
26 |
27 | - name: install local ptx files
28 | run: pretext --version
29 |
30 | - name: build deploy targets
31 | run: |
32 | version="$(pretext --version)"
33 | major="$(echo $version | cut -d '.' -f 1)"
34 | minor="$(echo $version | cut -d '.' -f 2)"
35 | if [ "$major" -ge 2 -a "$minor" -ge 5 ]; then
36 | echo "PreTeXt version is 2.5 or greater; using new build command"
37 | pretext build --deploys
38 | else
39 | echo "PreTeXt version is less than 2.5, using old build command"
40 | pretext build
41 | fi
42 | - name: stage deployment
43 | run: pretext deploy --stage-only
44 |
45 | - name: Bundle output/stage as artifact
46 | uses: actions/upload-artifact@v4
47 | with:
48 | name: deploy
49 | path: output/stage
50 |
51 | deploy-cloudflare:
52 | runs-on: ubuntu-latest
53 | needs: build
54 | if: vars.CLOUDFLARE_PROJECT_NAME != ''
55 | permissions:
56 | contents: read
57 | deployments: write
58 |
59 | steps:
60 | - name: Download artifact
61 | uses: actions/download-artifact@v4
62 | with:
63 | name: deploy
64 | path: deploy
65 | - name: Create 404.html
66 | run: echo "404 page not found" >> deploy/404.html
67 | - name: Publish to Cloudflare
68 | uses: cloudflare/pages-action@v1
69 | with:
70 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
71 | accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
72 | projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
73 | gitHubToken: ${{ secrets.GITHUB_TOKEN }}
74 | branch: ${{ github.head_ref || github.ref_name }}
75 | directory: deploy
76 |
77 | deploy-ghpages:
78 | runs-on: ubuntu-latest
79 | needs: build
80 | if: vars.PTX_ENABLE_DEPLOY_GHPAGES == 'yes' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
81 | permissions:
82 | contents: read
83 | pages: write
84 | id-token: write
85 | concurrency:
86 | group: "page"
87 | cancel-in-progress: false
88 | environment:
89 | name: github-pages
90 | url: ${{ steps.deployment.outputs.page_url }}
91 | steps:
92 | - name: Download website artifact
93 | uses: actions/download-artifact@v4
94 | with:
95 | name: deploy
96 | path: deploy
97 | - name: Setup GitHub Pages
98 | id: check
99 | uses: actions/configure-pages@v4
100 | - name: Upload artifact
101 | uses: actions/upload-pages-artifact@v3
102 | with:
103 | path: deploy
104 | - name: Deploy to Github Pages
105 | id: deployment
106 | uses: actions/deploy-pages@v4
107 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # (delete the above line to manage this file manually)
3 |
4 | # Boilerplate list of files in a PreTeXt project for git to ignore
5 | # ensure this file is tracked
6 | !.gitignore
7 |
8 | # don't track unpublished builds or stage (note: Runestone uses `published`)
9 | output
10 | published
11 |
12 | # don't track assets generated from source
13 | generated-assets
14 |
15 | # don't track the executables.ptx file
16 | executables.ptx
17 |
18 | # don't track node packages
19 | node_modules
20 |
21 | # don't track error logs
22 | .error_schema.log
23 | logs
24 |
25 | # don't track OS related files (windows/macos/linux)
26 | .DS_Store
27 | .DS_Store?
28 | ._*
29 | .AppleDouble
30 | .LSOverride
31 | .Spotlight-V100
32 | .Trashes
33 | Icon
34 | .AppleDB
35 | .AppleDesktop
36 | Network Trash Folder
37 | Temporary Items
38 | .apdisk
39 | Thumbs.db
40 | Thumbs.db:encryptable
41 | ehthumbs.db
42 | ehthumbs_vista.db
43 | *.stackdump
44 | *.lnk
45 | *.cab
46 | *.msi
47 | *.msix
48 | *.msm
49 | *.msp
50 | [Dd]esktop.ini
51 | .directory
52 | .fuse_hidden*
53 | .Trash-*
54 | .nfs*
55 |
56 | # Don't include VSCode generated files
57 | .vscode
58 | *.code-workspace
59 |
60 | # Don't inlucde SublimeText files
61 | # Cache files for Sublime Text
62 | *.tmlanguage.cache
63 | *.tmPreferences.cache
64 | *.stTheme.cache
65 |
66 | # Workspace files are user-specific
67 | *.sublime-workspace
68 |
69 | # Project files should be checked into the repository, unless a significant
70 | # proportion of contributors will probably not be using Sublime Text
71 | *.sublime-project
72 |
73 | # SFTP configuration file
74 | sftp-config.json
75 | sftp-config-alt*.json
76 |
77 | # Package control specific files
78 | Package Control.last-run
79 | Package Control.ca-list
80 | Package Control.ca-bundle
81 | Package Control.system-ca-bundle
82 | Package Control.cache/
83 | Package Control.ca-certs/
84 | Package Control.merged-ca-bundle
85 | Package Control.user-ca-bundle
86 | oscrypto-ca-bundle.crt
87 | bh_unicode_properties.cache
88 |
89 | # Sublime-github package stores a github token in this file
90 | # https://packagecontrol.io/packages/sublime-github
91 | GitHub.sublime-settings
92 |
93 |
94 | # Don't include Dropbox settings and caches
95 | .dropbox
96 | .dropbox.attr
97 | .dropbox.cache
98 |
99 | # Don't track codechat config (will be generated automatically)
100 | codechat_config.yaml
101 |
102 | # Don't track deprecated workflows
103 | .github/workflows/deploy.yml
104 | .github/workflows/test-build.yml
105 |
--------------------------------------------------------------------------------
/GenerateAssetsHelp.md:
--------------------------------------------------------------------------------
1 | # Help for LaTeX-based builds (PDF) and Generating Assets in PreTeXt-Codespace
2 |
3 | There are three docker images available trading off between size and functionality. If you find that the default "small" image leads to compilation errors when building LaTeX or when generating some assets, switch to the "full" tag. If you only build web targets and don't have any latex-image assets to generate, you can use the "lite" tag to save more space.
4 |
5 | To change the docker image, open the file `.devcontainer/devcontainer.json`, comment out the line starting with `"image":` and uncomment the appropriate alternative line below that.
6 |
7 | Once you save the `devcontainer.json` file, VS Code should offer to rebuild your container. You can also force a rebuild using the command pallet or clicking the "Codespaces" button in the bottom status bar.
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | This work is licensed under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0).
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GitHub for Mathematicians
2 |
3 | A handbook for mathematical researchers and instructors to start using GitHub services to
4 | maintain open and collaborative digital products.
5 |
6 | ## Contributing
7 |
8 | Contributions are very welcome! Please feel free to open an Issue or
9 | make a Pull Request to the main repository at
10 | Thanks for visiting! TODO TODO TODO
6 |
9 |
16 |
\n",
22 | "In the field type:
\n",
23 | "```python\n",
24 | "print('Hello, World')\n",
25 | "```\n",
26 | "Then press `
\n",
52 | "```python\n",
53 | "1 + 1\n",
54 | "```\n",
55 | "and execute the code."
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "metadata": {
62 | "scrolled": true
63 | },
64 | "outputs": [],
65 | "source": []
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {},
70 | "source": [
71 | "Now type\n",
72 | "```python\n",
73 | "20 + 80\n",
74 | "```\n",
75 | "and execute the code."
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": null,
81 | "metadata": {},
82 | "outputs": [],
83 | "source": []
84 | },
85 | {
86 | "cell_type": "markdown",
87 | "metadata": {},
88 | "source": [
89 | "These are additions. We can of course use other mathematical operators.
\n",
90 | "Try this subtraction:
\n",
91 | "```python\n",
92 | "6 - 5\n",
93 | "```"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "metadata": {},
100 | "outputs": [],
101 | "source": []
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "and this multiplication:
\n",
108 | "```python\n",
109 | "2 * 5\n",
110 | "```"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": null,
116 | "metadata": {},
117 | "outputs": [],
118 | "source": []
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "metadata": {},
123 | "source": [
124 | "Try:\n",
125 | "```python\n",
126 | "5 ** 2\n",
127 | "```"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": null,
133 | "metadata": {},
134 | "outputs": [],
135 | "source": []
136 | },
137 | {
138 | "cell_type": "markdown",
139 | "metadata": {},
140 | "source": [
141 | "`**` is the exponential operator, so we executed 5 squared."
142 | ]
143 | },
144 | {
145 | "cell_type": "markdown",
146 | "metadata": {},
147 | "source": [
148 | "Type:\n",
149 | "```python\n",
150 | "print('1 + 2 is an addition')\n",
151 | "```"
152 | ]
153 | },
154 | {
155 | "cell_type": "code",
156 | "execution_count": null,
157 | "metadata": {},
158 | "outputs": [],
159 | "source": []
160 | },
161 | {
162 | "cell_type": "markdown",
163 | "metadata": {},
164 | "source": [
165 | "You see that the `print` statement writes something on the screen.\n",
166 | "\n",
167 | "Try this:\n",
168 | "```python\n",
169 | "print('one kilobyte is 2^10 bytes, or', 2 ** 10, 'bytes')\n",
170 | "```"
171 | ]
172 | },
173 | {
174 | "cell_type": "code",
175 | "execution_count": null,
176 | "metadata": {},
177 | "outputs": [],
178 | "source": []
179 | },
180 | {
181 | "cell_type": "markdown",
182 | "metadata": {},
183 | "source": [
184 | "This demonstrates that you can print text and calculations in a sentence. The commas separating each section are a way of separating strings (text) from calculations or variable."
185 | ]
186 | },
187 | {
188 | "cell_type": "markdown",
189 | "metadata": {},
190 | "source": [
191 | "Now try this:\n",
192 | "```python\n",
193 | "23 / 3\n",
194 | "```"
195 | ]
196 | },
197 | {
198 | "cell_type": "code",
199 | "execution_count": null,
200 | "metadata": {},
201 | "outputs": [],
202 | "source": []
203 | },
204 | {
205 | "cell_type": "markdown",
206 | "metadata": {},
207 | "source": [
208 | "And this:
\n",
209 | "```python\n",
210 | "23 % 3\n",
211 | "```"
212 | ]
213 | },
214 | {
215 | "cell_type": "code",
216 | "execution_count": null,
217 | "metadata": {},
218 | "outputs": [],
219 | "source": []
220 | },
221 | {
222 | "cell_type": "markdown",
223 | "metadata": {},
224 | "source": [
225 | "`%` returns the remainder of the division."
226 | ]
227 | },
228 | {
229 | "cell_type": "markdown",
230 | "metadata": {},
231 | "source": [
232 | "## 1.3 Order of Operations"
233 | ]
234 | },
235 | {
236 | "cell_type": "markdown",
237 | "metadata": {},
238 | "source": [
239 | "Remember that thing called order of operation that they taught in maths? Well, it applies in Python, too. Here it is, if you need reminding:
\n",
240 | "1. Parenthesis `()`\n",
241 | "2. Exponents `**`\n",
242 | "3. Multiplication `*`, division `/` and remainder `%`\n",
243 | "4. Addition `+` and subtraction `-`"
244 | ]
245 | },
246 | {
247 | "cell_type": "markdown",
248 | "metadata": {},
249 | "source": [
250 | "Here are some examples that you might want to try, if you're rusty on this:
\n",
251 | "```python\n",
252 | "1 + 2 * 3\n",
253 | "(1 + 2) * 3\n",
254 | "```"
255 | ]
256 | },
257 | {
258 | "cell_type": "code",
259 | "execution_count": null,
260 | "metadata": {},
261 | "outputs": [],
262 | "source": []
263 | },
264 | {
265 | "cell_type": "code",
266 | "execution_count": null,
267 | "metadata": {},
268 | "outputs": [],
269 | "source": []
270 | },
271 | {
272 | "cell_type": "markdown",
273 | "metadata": {},
274 | "source": [
275 | "## 1.4 Comments, Please\n",
276 | "The final thing you'll need to know to move on to multi-line programs is the comment. Type the following (and yes, the output is shown):\n",
277 | "```python\n",
278 | "# I am a comment. Fear my wrath!\n",
279 | "```"
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": null,
285 | "metadata": {},
286 | "outputs": [],
287 | "source": []
288 | },
289 | {
290 | "cell_type": "markdown",
291 | "metadata": {},
292 | "source": [
293 | "A comment is a piece of code that is not run. In Python, you make something a comment by putting a hash in front of it. A hash comments everything after it in the line, and nothing before it. So you could type this:\n",
294 | "```python\n",
295 | "print(\"food is very nice\") #eat me\n",
296 | "```"
297 | ]
298 | },
299 | {
300 | "cell_type": "code",
301 | "execution_count": null,
302 | "metadata": {},
303 | "outputs": [],
304 | "source": []
305 | },
306 | {
307 | "cell_type": "markdown",
308 | "metadata": {},
309 | "source": [
310 | "This results in a normal output, without the smutty comment, thank you very much.\n",
311 | "\n",
312 | "Now try this:\n",
313 | "```python\n",
314 | "# print(\"food is very nice\")\n",
315 | "```"
316 | ]
317 | },
318 | {
319 | "cell_type": "code",
320 | "execution_count": null,
321 | "metadata": {},
322 | "outputs": [],
323 | "source": []
324 | },
325 | {
326 | "cell_type": "markdown",
327 | "metadata": {},
328 | "source": [
329 | "Nothing happens, because the code was after a comment."
330 | ]
331 | },
332 | {
333 | "cell_type": "markdown",
334 | "metadata": {},
335 | "source": [
336 | "Comments are important for adding necessary information for another programmer to read, but not the computer. For example, an explanation of a section of code, saying what it does, or what is wrong with it. You can also comment bits of code by putting a `#` in front of it - if you don't want it to compile, but can't delete it because you might need it later."
337 | ]
338 | },
339 | {
340 | "cell_type": "markdown",
341 | "metadata": {},
342 | "source": [
343 | "# Assignment 1\n",
344 | "\n",
345 | "Type in the cell below an expression to find out how many seconds are there in a 365-day year."
346 | ]
347 | },
348 | {
349 | "cell_type": "code",
350 | "execution_count": null,
351 | "metadata": {},
352 | "outputs": [],
353 | "source": []
354 | },
355 | {
356 | "cell_type": "markdown",
357 | "metadata": {},
358 | "source": [
359 | "# Assignment 2\n",
360 | "\n",
361 | "The Earth can be approximated as a sphere with a radius of 6370 km. Use the cell below to find out the volume of such a shape in cubic meters."
362 | ]
363 | },
364 | {
365 | "cell_type": "code",
366 | "execution_count": null,
367 | "metadata": {},
368 | "outputs": [],
369 | "source": []
370 | },
371 | {
372 | "cell_type": "markdown",
373 | "metadata": {},
374 | "source": [
375 | "# Assignment 3\n",
376 | "\n",
377 | "Get the answer of the following expression, using the cell below:\n",
378 | "\n",
379 | "$$\\frac{1}{2}+\\frac{\\frac{1}{3}}{\\frac{1}{4}+\\frac{1}{5}}$$"
380 | ]
381 | },
382 | {
383 | "cell_type": "code",
384 | "execution_count": null,
385 | "metadata": {},
386 | "outputs": [],
387 | "source": []
388 | }
389 | ],
390 | "metadata": {
391 | "kernelspec": {
392 | "display_name": "Python 3 (ipykernel)",
393 | "language": "python",
394 | "name": "python3"
395 | },
396 | "language_info": {
397 | "codemirror_mode": {
398 | "name": "ipython",
399 | "version": 3
400 | },
401 | "file_extension": ".py",
402 | "mimetype": "text/x-python",
403 | "name": "python",
404 | "nbconvert_exporter": "python",
405 | "pygments_lexer": "ipython3",
406 | "version": "3.11.4"
407 | }
408 | },
409 | "nbformat": 4,
410 | "nbformat_minor": 4
411 | }
412 |
--------------------------------------------------------------------------------
/assets/g4m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/code4mathorg/github-for-mathematicians/92ba1a88efa84e3a2c0fbf273768f266f27e3c3a/assets/g4m.png
--------------------------------------------------------------------------------
/assets/g4m.svg:
--------------------------------------------------------------------------------
1 |
2 |
198 |
--------------------------------------------------------------------------------
/assets/git-branches-source.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
--------------------------------------------------------------------------------
/assets/website-example.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/code4mathorg/github-for-mathematicians/92ba1a88efa84e3a2c0fbf273768f266f27e3c3a/assets/website-example.zip
--------------------------------------------------------------------------------
/project.ptx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
22 |
7 | While the quick
17 | A dev environment
service
18 |
23 | Full documentation on Codespaces is available on
24 |
30 | To create a Codespace on any repository you own, use the green
31 | Code
button, select the Codespaces tab, and press
32 | the green Create codespace on [branchname]
button.
33 |
36 | After the Codespace boots up, you'll have an interface similar
37 | to the
42 | Here are a few key differences between
43 |
47 | A
54 |
59 |
65 | You can only install applications and execute code on a Codespace. 66 |
67 |
72 | One similarity between
82 | One quick way to commit and push your changes from a Codespace
83 | is to use Source Control
from the left toolbar.
84 |
87 | Enter a short commit message describing 88 | your changes as a note to yourself. (This is 89 | required and can be a pain to fix if you forget 90 | to do so!) 91 |
92 |
95 | Select Commit & Sync
from the menu
96 | next to the green Commit button.
97 |
101 | In the dialogs that follow, I suggest choosing
102 | to Always
stage all your changes and commit them
103 | directly, then OK, Don't Show Again
when told
104 | this action will pull and push commits from and to
105 | Yes
that you
106 | would like your Codespace to periodically run
107 |
117 | Now that we've provisioned our Codespace virtual cloud computer, 118 | we can use it to write and execute code using our web browser for 119 | essentially any programming lanugage. 120 |
121 |
122 | Our first example will be Python, a popular general-purpose programming
123 | language (and the same language we will use in New File...
. Name this file
141 | Add the line play
icon (▶) should be displayed
143 | in the upper-right corner of the text editor (thanks to the
144 | Python extension you installed). Clicking
145 | this button should execute the code to print a greeting
146 | as in
157 | Unless your Codespace has been customized via a
158 |
168 | A
177 | To open a terminal on demand in a Codespace, use the shortcut 178 | Ctrl/Cmd+Shift+`. 179 |
180 |
183 | What do you think the programs in
184 |
247 | GitHub users are provided with a limited amount of free Codespace
248 | hours and storage each month, with additional resources available
249 | to Pro users, including those with the free GitHub Education
250 | benefit (
254 | As a mathematician
255 | who almost exclusively uses GitHub Codespaces for doing the kinds
256 | of work described in this handbook (and does so for much longer
257 | periods of time than a typical mathematician),
258 | I've only surpassed GitHub's free quota on the rare occassion
259 | (and when I do, I've paid only
265 | To manage your Codespace resources, visit
266 |
275 | In any case, a 276 | stopped Codespace can be restarted later when you want to 277 | resume work, even if you haven't committed and pushed your changes. 278 | (But be warned: a stopped Codespace and its uncommitted changes may 279 | be deleted by GitHub after a few days of inactivity, so don't leave it 280 | alone for long.) 281 |
282 |283 | A deleted Codespace can always be recreated later based upon your most 284 | recent commit. 285 |
286 |
289 |
Screenshot of a web browser. Its text follows:
303 |Default idle timeout
304 |A codespace will suspend after a period of inactivity. You can specify a default idle timeout value, which will apply to all codespaces created after the default is changed. You will be charged for the entire time your codespace is running, even if it is idle. The maximum value is 240 minutes (4 hours).
305 |Default retention period
306 |Inactive codespaces are automatically deleted 30 days after the last time they were stopped. A shorter retention period can be set, and will apply to all codespaces created going forward. The default and maximum value is 30 days. Learn about retention setting
307 |
311 | Putting it all together, we have seen three ways to access files on your repo.
312 | Going from the least easy to edit to the most editable we have:
326 | As of January 2025, a default codespace will use a
327 | 2-core processor and 8GB of RAM, with a quota of
328 | 60 usage hours and 15GB storage per month. (This is increased
329 | to 90 usage hours and 20GB storage for Pro/Education users.)
330 | This is fine for many tasks,
331 | but if you're doing data analysis (
337 | You can double (or quadruple, or changing the machine type
. There are several ways to accomplish
339 | this, via Change Machine Type
in the Codespace command pallette
341 | (accessed via Ctrl/Cmd+Shift+P).
342 |
344 | Note however, that if you double your resources, you are also doubling your 345 | usage time (e.g. running a 4-core machine uses one hour of your quota 346 | every 30 minutes). 347 |
348 |
353 | A key feature of Codespaces is that they can be customized by the use of a
354 |
361 | Setting up a custom It works on my machine
while I can't get it
365 | to work on my machine
!
366 |
368 | See
7 | A direct way to allow multiple people you trust to work on the 8 | same repository is to add these GitHub users as collaborators. 9 |
10 |
13 | A
25 | Collaborators are added by going to your repository's Settings tab, 26 | using the Collaborators link in the sidebar. Each collaborator will 27 | need their own GitHub account, and must accept the invitation to 28 | collaborate before gaining access. 29 |
30 |
31 | Once they have access, a collaborator can either use
37 | If two collaborators on the same repository make commits on
38 | the same branch, they will desynchronize your project's history:
39 | person A's history will think that commit
44 | As seen in
51 | Our recommendation to support multiple collaborators on the same
52 | repository is to never directly commit to the
56 | To commit to an alternative branch in Create new branch
. It's a good idea to name your
59 | branch in the form
67 | Once a collaborator is working on a branch, they are free to edit as 68 | they wish, and can (and should) commit and push/sync with GitHub to 69 | persist their contributions to the team's repository. 70 |
71 |72 | To facilitate communication among collaborators working on 73 | different branches, it's good practice to open a draft pull request 74 | once a new branch is created. 75 |
76 |
79 | A
86 | A PR can be marked as a
93 | Depending on whether the collaborator is using
99 | Recent pushes to a 100 | branch will reveal a prompt to create the pull request immediately. 101 | Otherwise, the PR can be created by using the Pull Requests tab 102 | of the page. 103 |
104 |
105 | Unless the PR is for a single commit that's immediately
106 | ready for review
, a new PR should be created as
107 | a draft.
108 |
111 | With a draft pull request created, the contributor can 112 | continue to commit and push/sync to the branch until it is 113 | ready for review. The discussion features of GitHub can allow 114 | contributors to discuss the proposed changes, whether they are in 115 | draft or review-ready status. 116 |
117 |119 | A draft pull request has a large button near the end of the 120 | discussion thread to mark the pull request as ready for review. 121 |
122 |123 | A ready for review pull request can be converted to a draft 124 | by using a small link on the right sidebar. 125 |
126 |
128 | Depending on the complexity or maturity of the project,
129 | you may wish to develop a review process with your collaborators,
130 | or simply use the PR workflow to clearly communicate when changes
131 | are being made to the main branch, and ensure no two collaborators
132 | make incompatible changes to the same branch. Whatever you choose,
133 | you'll eventually want to incorporate these branched changes into
134 | your
138 | There are several options for merging a branch's pull request.
139 | I recommend the Squash and Merge
option, which converts all
140 | the branch's commits/changes into a single new commit extending the
141 | target branch.
142 |
145 | As long as contributions are made using appropriate branches
146 | and pull requests, you will have minimal problems with conflicting
147 | changes made between different collaborators, with GitHub handling
148 | the merging process automatically, even if two collaborators edit
149 | the same file. (But not always, see
152 | But a common error that I frequently make myself: what if you forget
153 | to create a branch with your work, and you acccidentally commit
154 | to
160 | To prevent unintended changes to your Branch name pattern
, and
165 | enabling required pull requests.
166 |
172 | Unfortunately, there's no button to push that will fix a commit
173 | made to the local copy of
178 | This fix must be done in a Codespace, 179 | not GitHub.dev. 180 |
181 |
184 | With branch protection
191 | To fix this, open a Terminal
192 | (
198 | Then, copy-paste
228 | One great thing about working with open source on GitHub is that 229 | not only can you collaborate with your trusted colleagues, but 230 | you can also work with collaborators who do not have write access 231 | to your repository. 232 |
233 |
236 | A
243 | Managing contributions from forked repositories is done using the
244 | same workflow as we recommend for collaborating with trusted colleagues
245 | that you've given write access to your repository
246 | (
256 | To create a fork of a public repository, press the Fork
button
257 | on its upstream
contributions by way of
260 | pull requests.
261 |
264 | Those of us who work in open source typically love getting
265 | pull requests from random collaborators. For example, if you find a
266 | typo in this book, you can fxi
267 | it by creating a fork at
268 |
276 | Perhaps the most complicated scenario when collaborating 277 | on a Git repository is the dreaded merge conflict. 278 |
279 |
282 | While Git is fairly good about merging together changes
283 | made by different contributors to different
284 | files within a project into a cohesive whole, a
285 |
294 | Handling merge conflicts can be tricky!
295 | Git/GitHub have various tools to help you review and correct
296 | a merge conflict. If you're fortunate, you'll be able to resolve
297 | things on the pull request page: see
298 |
303 | You'll be presented with files with some strange markers as in
304 |
324 | You can then choose which change to retain, deleting all the
325 | extra
330 | However, sometimes the merge conflict is too involved to be
331 | corrected using the web interface. In that situation, you will
332 | need to use a Codespace and follow the instructions at either
333 |
10 | In this chapter we will explore GitHub's
14 | Note that almost everything in this chapter will likely be out of date almost immediately.
15 | The current suggestions here are up to date as of
23 |
27 | Depending on what you want to do with your project, other AI assistants might be a better fit.
28 | One notable alternative that might work even better for coding projects is
34 | All of the specific commands described below will be those of Copilot, but often the same commands will work with Codeium. 35 | In any event, we will focus on general principles of how to use these coding assistants. 36 |
37 |
43 | We will assume you want to use Copilot from inside VS Code, either on your own machine or in a Github Codespace.
44 | To get set up, follow the
48 | In particular, make sure you have 49 |
52 | Enabled Copilot in your Github account. 53 |
54 |58 | Installed the Copilot extension in VS Code. 59 |
60 |65 | That should be it. 66 |
67 |73 | There are three main ways you can interact with Copilot from inside VS Code: 74 |
77 | By accepting ghost text
suggestions as you type.
78 | Copilot will will show you the most likely words to appear next to your cursor in light gray text.
79 | Hitting
85 | Use Copilot Chat by clicking the Copilot icon at the top of the VS Code window, right of the search bar (see Open chat
to open a panel on the right side of the window.
87 | This panel allows you to Ask Copilot
questions, similar to using ChatGPT or another AI chatbot.
88 | The key difference is that Copilot uses your current file or workspace (or another selected source) as its context.
89 | You can also use voice commands to ask questions and have Copilot read its answers aloud.
90 |
95 | By using Copilot's
117 | Here are a few features of Copilot you might want to try out. 118 |
121 | Suppose you are trying to write some code in a language you are not that familiar with.
122 | Copilot will suggest the next bit of code for you as you type.
123 | To get better suggestions, put in a comment describing what you want to do.
124 | (Hint: if you don't know the syntax for comments, hit
130 | Does the code do what you want it to? Is it confusing? Ask Copilot to explain the code to you.
131 | You can select the code, hit
137 | Along these lines, try asking Copilot to document your code for you.
138 | Select the code, hit
144 | Here is something I just did while writing this.
145 | I realized that I wanted all the keyboard shortcuts to be displayed as code, which in wrap all keyboard shortcuts here with
Copilot then let me see where it made changes (line by line) and let me accept them or not.
147 |
150 | A very new Copilot feature is
157 | If you are working on a mathematical proof or a complex equation, you can ask Copilot to help you format it correctly in LaTeX.
158 | Simply type your equation or proof in plain text, select it, hit
163 | NOTE: I don't know if that's true, the above paragraph was generated by Copilot from the prompt Write a suggestion of something Copilot can do for a mathematician.
164 |
170 | One final thing you might want to try: Disable completions.
You can also disable completions for particular types of files.
173 |
7 | All the features of GitHub we'll be using are available 8 | using a free GitHub account. 9 |
10 |
12 | Anyone can create a free GitHub account by
13 | visiting
17 | For additional free resources, you may also be eligible for 18 | a waiver. 19 |
20 |
22 | Many students and faculty of schools, colleges, and universties
23 | are eligible to request an
24 | educator discount, providing Pro
features at no cost,
25 | by visiting
26 |
31 | You do not need to wait for approval of your educator 32 | discount before continuing to the next section. 33 |
34 |
38 | Once logged in, a new repository can be created by
39 | pressing the + button in the toolbar,
40 | or visiting
43 | The repository will need a name, which can be something
44 | like
49 | Repositories can be
59 | The last option we'll make sure to select is to
60 | Initialize this repository with:
61 | Add a README file
. Then click Create repository
.
62 |
67 | While logged into
74 | An easy way to edit an individual file is just to click
75 | the pencil icon such as the one that appears on your README.
76 | This file is written in Markdown
.
77 |
81 | like this
. Sites like
84 |
91 | Try to edit your file to say something like I'm learning how to
92 | use GitHub!
, perhaps adding a link back to this document
93 | using
99 | When you're happy with your updated README, click the
100 | Commit changes
button. This will create a new
101 | Update README.md
)
105 | Doing this will update the README visible on your repository
106 | homepage on
110 | README files are important! If you ever want to share your 111 | repository source with someone else, it's the first thing 112 | they will read. Likewise, if you want to use someone else's 113 | repository, they will hopefully include first steps in their 114 | own README file. 115 |
116 |
118 | Finally, you might be interested in visiting the Insights
119 | tab for your repository, and specifically the Network
page.
120 | It should reveal a graphic similar to
131 | Using the
139 | One way to quickly be able to manage several files at once is
140 | to use the
146 | It's best to use an updated version
147 | of Chrome, Edge, or Firefox when using GitHub. In particular, Safari tends
148 | to show off its rough edges when using advanced web applications like
149 |
153 | You can create files, edit them, upload images, and do whatever you
154 | like at
160 | There are two very easy ways to access the
168 | The other trick is even fancier. When you are visiting
169 |
174 | Either way, you should now have a
189 | After you're tried creating/editing/uploading a few files, now it's
190 | time to commit those changes to your repository. The easiest way
191 | to do this is to use the
198 | Clicking these
199 | file names not only lets you open the file and edit it further, but you
200 | are shown a
206 | The idea is this: edit as you see fit, knowing that your files are being
207 | saved at learning GitHub.dev
.) Then once you click
214 | the Commit and Push
button, your work will be logged as a permanent
215 | commit to the repository.
216 |
218 | This is a good point to review your commit history again. You probably
219 | have three commits: the initial commit made when you created the repository,
220 | the 3 commits
link
224 | from your
233 | Now that you've gotten the hang of the basics of
234 | committing and pushing changes to a repository,
235 | you can move on to using Codespaces to write
236 | and execute programs and code (
16 |
25 | Two core concepts of Git are feature branch
back into
32 | the main branch
when it's complete. This is particularly
33 | useful when multiple people collaborate
34 | (
39 | Since you're reading
40 |
55 | Another key feature of Git is the ability to share
56 | your project, along with its history, with other people.
57 | This is generally accomplished by hosting your repository
58 | on a service such as
65 | Importantly, GitHub
66 | is not itself open-source software, but is a service owned and operated
67 | by Microsoft. However, Microsoft makes GitHub available for use at no cost to the public,
68 | with additional pro
features available for free to instructors and researchers.
69 |
71 | We'll use GitHub not only as a host for our repositories, but also
72 | to take advantage of all the tools it provides to author content
73 | using only a web browser. If you've looked into using Git in the past,
74 | you may have hesitated due to the apparent need for software developer
75 | experience to get started. However, using GitHub's web applications,
76 | there will be no need for complicated installations or
77 | memorizing command line incantations like
84 | Another reason to use GitHub: community! GitHub is often marketed as a
85 | social coding platform
, because it not only provides tools to create
86 | and deliver digital content, but it also provides social features such as
87 | Following users, Starring repositories, participation in Discussions and Issues,
88 | and more. Particular in open-source, we like to work together and support each other,
89 | and GitHub provides much of the social cyberinfrastructure necessary to do so
90 | efficiently.
91 |
96 | An example of a project using Git and GitHub is the
97 | document you're reading right now!
98 | This book is open-sourced and shared at
99 |
6 | In
18 | A
25 | Jupyter is a popular open-source tool used in
26 | data science, scientific computing, and computational journalism.
27 | GitHub provides a Codespace ready for running Jupyter notebooks
28 | out of the box:
29 |
35 | Let's begin by going to
36 | IPYthon NoteBook
,
43 | Jupyter's original name).
44 |
46 | Clicking on each file, you'll note that while there's code, 47 | most of the file is actually narrative and visualization. 48 | That's the appeal of Jupyter for many people: it's about 49 | communicating stories, not just data or software. 50 |
51 |
52 | Additionally, you'll see a
58 | Now, let's follow the instructions of the repository's
59 | README file (try out
the Codespace
63 | without saving your work long-term, but you can still create a fork
64 | with your changes later if you decide to.
65 |
70 | At the core of any Jupyter notebook is its kernel
.
71 |
75 | The
81 | Kernels for several different programming languages exist. We will use 82 | a Python kernel in this book, not least of which because it's one of the 83 | most commonly used kernels, and the kernel that's already set up for use 84 | with the GitHub Jupyter Codespace repo. 85 |
86 |
87 | In your Codespace, use the Select kernel
button, to choose
88 | a Python environment
. You should be able to select the default
89 | global environment without needing to create a new one. Your notebook
90 | is ready once you see
97 | A notebook is composed of many consecutive parts, known as cells
.
98 |
102 | A
110 | Each Markdown cell uses, well, Markdown (
115 | But it's the Code cells that set a notebook apart. Each Code cell
116 | in a notebook is run consecutively, with the result of the final
117 | line of code being displayed for the reader. Importantly, these
118 | outputs are saved to the notebook itself, meaning that by sharing
119 | the notebook with a colleague, they can see the output of your
120 | code without running it themselves! This is not only convenient,
121 | but it's essential when communicating the result of code that
122 | uses software your reader does not have installed themselves.
123 | Likewise, it allows for showing the results of code via a web
124 | browser, such as at
125 |
131 | I've provided a
132 |
139 | A (possible) disadvantage of using Codespaces compared to your
140 | own computer is that all processing happens in the cloud, so
141 | you're limited by the resources made available to you by
142 | GitHub. But
150 | To use R instead of Python with your Jupyter notebook,
151 | a custom dev container (
6 | This chapter is co-authored by
12 | Math Animation
.
13 | The
20 |
25 |
31 | Manim provides tools that can bring mathematical ideas and concepts to life that
32 | static words and explanations may not capture. As an example, the
33 |
45 | A turn-key repository for creating a Codespace
46 | (
59 | Let's run our very first Manim animation. 60 |
61 |
65 | Open
72 | Open a Terminal and execute the command
73 |
82 | Open the file
83 |
91 | See if you can add these lines to the code so
92 | the video ends by saying My name is YOUR NAME HERE
.
93 |
96 |
101 |
114 | See if you can make the circle
130 | Open
134 | Review the comments and the code within this block.
135 | This particular scene
145 | Run
155 | Edit the code to find and display the line tangent
156 | to the curve when
164 | Change the window so that
173 | Choose a function
185 | The web-based
195 | Open
199 | This particular block of code plots a transformed sine function
200 | of the form
209 | Run the code to produce a video file. 210 |
211 |
217 | Edit the array
225 | Edit the array
233 | Edit the array
246 | Open
252 | The scene
260 | Run the function
266 | Pick your favorite product of functions and edit the code to 267 | produce the appropriate derivation. 268 |
269 |
273 | Copy and paste the
280 | Edit this new command to display an animation for your favorite 281 | chain rule derivation. 282 |
283 |
290 | Open
294 | This code displays a Riemann sum for a funcion, and displays the ongoing sum for
295 |
302 | Run the code to see the output. 303 |
304 |
311 | Change the function to a function of your choice. You may need to resize the window.
312 | Recall the identitites
329 | Here are a list of helpful links regarding Manim authoring: 330 |
333 |
341 |
349 |
357 |
365 |
7 |
15 | PreTeXt is particularly well-suited for the creation of
16 | interactive and accessible Open Educational Resources in
17 | mathematics and computer science. Works authored in PreTeXt
18 | can be deployed to
19 |
24 | The
25 |
33 |
45 | To paraphrase Mary Ellen Rudin, topology is a dense forest of
46 | counterexamples, and a usable map of the forest is a fine thing.
.
47 | The
55 | To learn how to contribute to the
64 | The
69 | The textbook
70 |
77 | (For a more casual experience outside GitHub, the
78 |
85 | In December 2023, the American Institute of Mathematics
86 | hosted a workshop of researchers to explore the future
87 | of sociotechnical infrastructure for mathematics. One outcome
88 | of this work was the establishment of
89 |
96 | The PROSE Consortium is a community of
97 | instructors, developers, and researchers focusd on open-source
98 | tools and resources for mathematics and computer science education.
99 | You can engage with this group by visiting their homepage at
100 |
7 | Having made your first repository in
13 | Another option is to use
21 | Use
26 | Create a file named
34 | Create an
47 | Download
48 |
60 | Commit this update to your repository using Source Control,
61 | and confirm you see the two new files on your
66 | To enable GitHub Pages, go to your repository Settings, and choose
67 | Pages from the sidebar. From there you can select to
68 | Deploy from a branch
, using the
78 | Once enabled, GitHub will provide a link to your public GitHub Pages
79 | website, hosted at
86 | It's good to remember how to 87 | distinguish the three GitHub domains: 88 |
91 |
97 |
105 |
113 | I recommend you add a link to your
118 | On your repository page, you can edit the About
sidebar
119 | to add useful information about your project. In particular,
120 | there's a checkbox to automatically
121 | display your
130 | While you can create a custom website by authoring HTML, it'd be
131 | great to not have to! There are several templates
available for
132 | GitHub Pages that allow you to author your content in Markdown,
133 | as well as providing nice themes, automatic linking between different
134 | sections of your website, and so on.
135 |
172 | A
179 | This is meant for situations like a GitHub Pages website, where 180 | you probably don't care about every single change that was made to create the 181 | template you're using, and you don't plan on contributing any of your changes 182 | back to the original repository. Instead, 183 | you just want the latest working files so you can insert your own 184 | content and get it online. 185 |
186 |
187 | Visit
188 | Use this template
, and Create a new repository
.
192 | This creates a new repository you own on About
sidebar, see
202 |
206 | Deploying to GitHub Pages can take some time, so visiting the
207 | Actions
tab on your repository page will let you see how this
208 | process is progressing. You can also see the status of this process
209 | by looking for the following icon next to your commit message:
210 | an orange dot (in progress), a green checkmark
211 | (deployed), or a red X (failure).
212 |
223 | Now that you have the template website hosted by GitHub Pages, you of course
224 | will want to customize it to yourself. For this book, I'll get you started by
225 | handling a few of the obvious first steps, assuming you're
226 | using the
232 | First things first, let's configure some basic elements of your site.
233 | These settings are found in
241 | To see that this worked, use Source Control to Commit and Push your
242 | edits. After a while (
254 | Next, let's add your photo. A placeholder is available
255 | at
263 | By default you have five files in your
269 | The
288 | Below the metadata is Markdown source that can be edited to include 289 | whatever content you'd like to appear within the page. 290 |
291 |
292 | To create additional pages, copy-paste
You can preview a compiled version of your markdown files (
309 | Posts are similar to pages, and live in the
315 | The content of your post is just Markdown, as with pages. However,
316 | you have slightly different metadata to edit (
344 | Another useful application of Codespaces is the ability
345 | to preview your GitHub Pages site created in
346 |
351 | To spin up your live preview, open a terminal by using the
352 | shortcut noted in
358 | You'll see some output, and eventually
359 | Your application on port 4000
361 | is available
. You can use its Open in browser
button,
362 | or hover over the
366 | This should open a URL such as
367 |
377 | Personally, I use
17 | This work includes materials used under license from the 18 | following works: 19 |
20 |CC BY-SA 4.0
29 |CC BY 3.0
40 |30 | Increasingly, the cyberinfrastructure of mathematics 31 | and mathematics education is built using GitHub to 32 | organize projects, courses, and their communities. 33 | The goal of this book is to help readers learn the basic features 34 | of GitHub available using only a web browser, and how 35 | to use these features to participate in GitHub-hosted 36 | mathematical projects with colleagues and/or students. 37 |
38 | This book was authored in
5 | Thanks to the following people who've contributed to this 6 | handbook. 7 |
10 | The
18 | Jeremy Avigad, for adding Codespaces support to his book
19 |
24 | Francesca Gandini and Brandon Sisler, for co-organizing the 25 | JMM 2024 professional 26 | enrichment program that this book was written for originally. 27 |
28 |31 | Tien Chih and Oscar Levin for contributing chapters on 32 | AI and Manim, repsectively. 33 |
34 |